Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Fri Jun 04, 2010 11:05 pm   

[3.18d-] BUG?: Quotations within expanded var preventing variable expansion.
 
This is related to versions before 3.18.

This is the point I was trying to make in http://forums.zuggsoft.com/forums/viewtopic.php?p=157221#157221. If quotations, within an expanded string, are to be displayed and not stripped, then it doesn't make sense for anything inside those quotations to be treated as a literal string.

Current case:

Code:
testvar = "cake"
#print {Testvar: "@testvar"}


Quote:
Testvar: "@testvar"


What I would expect to be printed:

Quote:
Testvar: "cake"
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: 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
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: 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.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: 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.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net