|
phranq Beginner
Joined: 11 Jul 2006 Posts: 13
|
Posted: Sat Aug 18, 2007 6:24 am
@%1 ... can't do it anymore? |
I need to send something in an alias like this.
#alias (abc) {~abc @%1}
@123=xyz
abc 123
abc xyz
right now it will send
abc @123
How do I get it to expand using the @%1 method? |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Aug 18, 2007 6:31 am |
The correct syntax is:
#alias (abc) {~abc @{%1}}
Indirect variable references always looks like @{stringvalue} where "stringvalue" is the string that represents the name of the variable you wish to expand. |
|
|
|
phranq Beginner
Joined: 11 Jul 2006 Posts: 13
|
Posted: Sat Aug 18, 2007 6:42 am |
I could've sworn I tried that, but it works!
I think I tried every variation with brackets and parentheses, but missed that one somehow... thanks. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sat Aug 18, 2007 12:50 pm |
I had trouble with a variation on this the other day, too.
Code: |
#for (health|mana) {#show @{concoctions.%i}}
#for (health|mana) {#show @concoctions.%i} |
Second one works, first one doesn't--this seems wrong? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Aug 18, 2007 12:52 pm |
That is rather strange, and it does seem wrong. I remember people mentioning that @{dbvar.key} worked before with dynamically-named keys :S
|
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Sat Aug 18, 2007 5:02 pm |
Something else I noticed: @var compiles into a VARREF, and @{var} into a USERFUNC. Any speed difference between the two?
Sometimes you have to use @{var} if referenced in the middle of text, as in "@{var}East". The parser could perhaps tell whether "var" is a string literal or not, and compile them the same way. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sat Aug 18, 2007 5:16 pm |
Good call. As a temporary workaround, @var~text works (compiles as varref) (for some uses at least?, I don't have a lot of test cases).
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Aug 18, 2007 5:24 pm |
Quote: |
@var compiles into a VARREF, and @{var} into a USERFUNC. Any speed difference between the two? |
Yes! A VARREF is a direct compiled reference to a variables location in the database. A USERFUNC is an indirect variable reference, and it needs to lookup the variable by name at run-time. Even though the lookup uses a hash table, indirect variable references will always be a bit slower than direct references.
I'll look into the bug with @{dbvar.key} and see what's happening there.
Quote: |
"@{var}East". The parser could perhaps tell whether "var" is a string literal or not, and compile them the same way. |
I'll see if I can add that optimization to the compiler. |
|
|
|
|
|