Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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

May
12,845
164
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:\>
 
Well, it is documented; see the next-to-the-last line in HELP ALIASES.
 
Of course you can parse %$ yourself using @WORD or @FIELD. Or @PARSEW or @PARSEF -- which I just discovered after writing PARSEARGS; sigh....
 
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
 
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").
 

Similar threads

Back
Top