1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Support' started by vefatica, Aug 24, 2012.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,794
    Likes Received:
    29
    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:\>
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    Well, it is documented; see the next-to-the-last line in HELP ALIASES.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,794
    Likes Received:
    29
    Thanks. And I figure that in my first example, %$ is getting appended right after "do i=1 to %#", making for faulty DO syntax.
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    Of course you can parse %$ yourself using @WORD or @FIELD. Or @PARSEW or @PARSEF -- which I just discovered after writing PARSEARGS; sigh....
     
  5. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,179
    Likes Received:
    11
    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
     
  6. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,179
    Likes Received:
    11
    Charles, what is @PARSEW and @PARSEF?

    -Scott
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    Functions in Vincent's 4UTILS plugin which chop a string up into words (fields) and stash them in an array.
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,794
    Likes Received:
    29
    Jeeez! I forgot about them.
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,794
    Likes Received:
    29
    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").
     
  10. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I just know parsec ;)
     

Share This Page