|
Derar Novice
Joined: 09 Sep 2006 Posts: 44
|
Posted: 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:
Also fails. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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. |
|
|
|
Derar Novice
Joined: 09 Sep 2006 Posts: 44
|
Posted: 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? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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.
|
|
|
|
|
|