WAD DO i=1 TO %# in an alias?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
It works in a BTM. Why not in an alias?
Code:
v:\> type hash.btm
do i=1 to %# ( echo %[%i] )
 
v:\> hash.btm 1 2 3
1
2
3
 
v:\> alias ee
do i=1 to %# ( echo %[%i] )
 
v:\> ee 1 2 3
Usage : DO [n | FOREVER]
 
v:\>
Below, apparently, %[%i] is not evaluated correctly.
Code:
v:\> alias ee
do i=1 to %# ( echo %[%i] ) & echo %$
 
v:\> ee 1 2 3
ECHO is OFF
ECHO is OFF
ECHO is OFF
1 2 3
 
v:\>
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#5
If you type: ee 1 2 3Ctrl+F
The alias is expanded and shows you what will be executed. The reason for the error statement is it gets expanded to:
Code:
do i=1 to 3 ( echo %[%i] ) 1 2 3
Your second alias doesn't error because it expands to:
Code:
do i=1 to 3 ( echo %[%i] ) & echo 1 2 3
-Scott
 
#9
Functions in Vincent's 4UTILS plugin which chop a string up into words (fields) and stash them in an array.
It's nice to know that you can (perhaps with some difficulty) parse an alias's %$ with DO. These two aliases seem to work the same.
Code:
v:\> alias e
for %f in ( %$ ) if not exist %f touch /q /c %f & textpad %$
 
v:\> alias ee
do i=0 to %@dec[%@parsew[foo,%$]] ( if not exist %foo[%i] touch /c /q %foo[%i] )
& unsetarray foo & textpad %$
Charles, I'll second your suggestion about "DO /W" (or suggest that "DO /L" simply be changed to respect the grouping of tokens into a single "string").