|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Mon Jul 19, 2004 5:07 pm
%1 expansion? |
I noticed that if you make an alias like:
Code: |
#ALIAS move {
path=""
#if (not %null( %1)) {
#if (%begins( %1, ".")) {
#echo Detected .path
temp=%right( %1, 1)
; Now build the path
path=%subregex( @temp, "(\d)(\a+)", %concat( "%repeat(%2|,%1)"))
} {path = %1}
#echo Added @path
} {%pop( path)}
}
|
Then the parser will expand %2, %1 in %repeat when the alias is called with for example "move .n" - even though it is surrounded with double quotes. Is this really correct behaviour? |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Jul 19, 2004 5:45 pm |
Yes.
%1 is normally expanded first, before the rest of the alias is evaluated. Placing it inside double-quotes delays the expansion to the same time that other variables would be expanded, but that still occurs as part of the alias execution. Use %%1 if you don't want it expanded by the alias. |
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Mon Jul 19, 2004 6:17 pm |
LightBulb wrote: |
Yes.
%1 is normally expanded first, before the rest of the alias is evaluated. Placing it inside double-quotes delays the expansion to the same time that other variables would be expanded, but that still occurs as part of the alias execution. Use %%1 if you don't want it expanded by the alias. |
I'm sorry but that doesn't seem to work.
Code: |
#ALIAS move {
path=""
#if (not %null( %1)) {
#if (%begins( %1, ".")) {
#echo Detected .path
temp=%right( %1, 1)
; Now build the path
path=%subregex( @temp, "(\d)(\a+)", %concat( "%repeat(%%2|,%%1)"))
} {path = %1}
#echo Added @path
} {%pop( path)}
}
|
This is what I get:
> move 2n
Detected .path
Added
This is what should happen:
> move 2n
Detected .path
Added n|n|
If I change the line
path=%subregex( @temp, "(\d)(\a+)", %concat( "%repeat(%%2|,%%1)"))
to
path=%subregex( @temp, "(\d)(\a+)", %concat( "%repeat(%", "2|,%", "1)"))
Then the script behaves correctly. Any idea why? Thanks for helping me. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Jul 19, 2004 9:19 pm |
Several other commands and functions also use numbered parameters, including #IF.
#ALIAS uses first %
#IF uses second %
Nested #IF uses third %
You need four of them! |
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Tue Jul 20, 2004 9:56 am |
LightBulb wrote: |
Several other commands and functions also use numbered parameters, including #IF.
#ALIAS uses first %
#IF uses second %
Nested #IF uses third %
You need four of them! |
That actually works . That is something I haven't seen before but looking it up in the help file I found out it is mentioned in the page about aliases. Thanks for helping me. |
|
|
|
|
|