 |
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
|
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Fri Jun 04, 2010 11:22 pm |
Why in the world would you expect that? You just made it a literal string by wrapping it in quotation marks, but then turn around and want it expanded to show the value? By wrapping it in quotes you are saying DON'T expand the variable. This is the same way in any programming language. You have to concatenate it to the string and store it in a local variable and then print it or don't use quotes and wrap the whole thing in the brackets like you did.
Example:
| Code: |
$msg = %concat("Testvar: '", @testvar,"'")
#print $msg |
|
|
|
|
 |
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Fri Jun 04, 2010 11:45 pm |
Because if " is to signify a literal string, within an expanded string, then why should it be printed as well? If I do #print "blah", I don't expect the quotations to be printed there.
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 05, 2010 5:28 pm |
Well, I can see what General is saying. I think it's going to be confusing either way we do it.
As a comparison, I tried playing with this in PHP since I want zScript to work like other "normal" languages. In PHP, the " quote is used to allow variable expansion, and the ' single quote is used to prevent expansion. So the " in PHP is like the {} in CMUD, and the ' in PHP is like the " in CMUD. For example, do the following in PHP:
| Code: |
$var=123;
print '$var not expanded';
print "$var is expanded"; |
and you will see
| Code: |
$var not expanded
123 is expanded |
OK. So now do this in PHP:
| Code: |
| print "$var expanded 'within quotes $var' test"; |
and you get
| Code: |
| 123 expanded 'within quotes 123' test |
This illustrates that the ' quotes within the " *are* printed, but that the $var *is* expanded even though it's within ' quotes within the " quotes.
So, General is perfectly correct to request this since that is how it would work in PHP. However, when I look at allowing @var to be expanded within " quotes when they are within {}, it breaks too many existing scripts in my parser tester program. CMUD has always had the fundamental parsing rule that nothing is expanded within " quotes, NO MATTER WHAT. Too much of CMUD is based upon that to change it now, sorry.
The correct way to get your original example to work is this:
| Code: |
testvar = "cake"
#print {Testvar: ~"@testvar~"} |
Since I'm not going to change the fact that variables are never expanded within " quotes, then we are back to the original question as to whether the quotes should be striped or not. |
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 05, 2010 5:31 pm |
| Quote: |
| If I do #print "blah", I don't expect the quotations to be printed there. |
That is a bad example because NO language would display the quotes in that example regardless of anything we are talking about here.
Again I would point at the PHP example above which *does* display the quotes (even though it also expanded the variable).
So I personally think the current case where CMUD displays the quotes but does not expand the variable is reasonable. |
|
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jun 06, 2010 5:09 pm |
Okay my mistake for saying "any". However, the only languages I have seen that behave that way for variable interpolation are Perl and PHP.
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jun 07, 2010 5:05 pm |
Most languages (compiled languages) do not have the concept of two different kinds of quotes where one kind allows expansion and the other doesn't. It's really only interpreted languages (like Perl and PHP) that have this concept. CMUD borrows heavily from Perl and PHP, so I often use them as examples.
|
|
|
|
 |
|
|
|