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
Derar
Novice


Joined: 09 Sep 2006
Posts: 44

PostPosted: Tue Aug 10, 2010 3:55 am   

[3.22] Deep db.$local.key syntax
 
Syntax that layers further key nesting after a variable does not work on the left side of the assignment operator. Seems to work just fine on the right side.

Code:

$db = @db.$var.layer1.layer2.layer3.$var2.key


Works just fine.

Code:

db.$var.layer1 = $db


Does not work.

Code:

#LOCAL $var, $db
db.layer1.layer2.layer3.$var = $db


Also works.

Looks like the parser, when seeing nesting syntax like this on the left side, stops parsing after the first local variable in the nest. It shows a syntax error as well (in the non-working example, the error is 'illegal token: .layer1 = $db at row 2 col 9'.

Edit: Changed the post slightly - this happens with any kind of variable reference, not just local, so:

Code:

db.@var.layer1 = $db


Also fails.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Aug 10, 2010 3:52 pm   
 
Yep, that is true. It is because the syntax is ambiguous. It doesn't know if you want to do this:
Code:
(db.$var).layer1 = $db

or this
Code:
db.($var.layer1) = $db

Since CMUD doesn't (currently) have any way to distinguish between these two cases, it gives an error. This problem happens no matter if it's a local variable or a standard variable. If we can decide which choice makes the most sense, then maybe I could remove the error.
Reply with quote
Derar
Novice


Joined: 09 Sep 2006
Posts: 44

PostPosted: Tue Aug 10, 2010 4:25 pm   
 
If it's a forced choice, I would argue that the first option is the more sensible; I think it's a more intuitive action to descend through the nesting.

One would expect application of the second to be a simple key reference, which can be handled by resetting $var to $var.layer1 anyway (so, db.$var = $db)

In the event that $var.layer1 is in fact another nested set you're putting through, maybe we can keep the option to provide the brackets to indicate that separation?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Aug 10, 2010 8:40 pm   
 
I'm not convinced that either interpretation is more logical than the other, so I think it is reasonable to require the user to explicitly distinguish which he means.
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