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

@EVAL, "AND" vs. "&"

Discussion in 'Support' started by vefatica, Mar 4, 2011.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,934
    Likes Received:
    30
    They don't seem to work the same:.

    Code:
    v:\> echo %@eval[( %_minute AND %_minute ) / %_minute]
    1
    
    v:\> echo %@eval[( %_minute & %_minute ) / %_minute]
    Eval warning: 'sdivide', Divide by 0
    TCC: Divide by zero "( 20 & %_minute ) / %_minute"
    It would seem that the parsing stopped early.

    And what's with the "Eval warning"? It doesn't appear in other similar circumstances.

    Code:
    v:\> set x=2 & set y=2 & set z=2 & set a=2
    
    v:\> echo %@eval[(%x AND %y) / %z]
    1
    
    v:\> echo %@eval[(%x & %y) / %z]
    TCC: Divide by zero "(2 & %y) / %z"
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,299
    Likes Received:
    39
    Well, the ampersand is the command separator. What happens if you escape it? Or do e.g. SETDOS /C0x13FF first?
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,934
    Likes Received:
    30
    On Fri, 04 Mar 2011 21:48:37 -0500, Charles Dye <> wrote:

    |Well, the ampersand is the command separator. What happens if you escape it? Or do e.g. SETDOS /C0x13FF first?

    Command separators are generally OK inside variable functions. Escaping it
    works but that shouldn't be necessary. It is certainly not neseccary if there's
    no variable substitution needed at all, or if variables (env only) are mentioned
    without the '%'.

    Code:
    v:\> echo %@eval[(2 & 2) / 2]
    1
    
    v:\> set x=4 & set y=7 & set z=2
    
    v:\> echo %@eval[(x & y) / z]
    2
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    If you have variables, the line has to be passed back to the variable
    expansion, and if you haven't quoted or escaped the & it will be treated as
    a command separator.

    It's worked that way forever.

    Rex Conn
    JP Software
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,934
    Likes Received:
    30
    On Fri, 04 Mar 2011 22:46:13 -0500, rconn <> wrote:

    |If you have variables, the line has to be passed back to the variable
    |expansion, and if you haven't quoted or escaped the & it will be treated as
    |a command separator.
    |
    |It's worked that way forever.

    I thought exactly that and that it was a bug. Most users (including myself)
    aren't very savvy when it comes to the working of the parser. The help merely
    says "& same as AND".
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: rconn
    | Quote:
    || Command separators are generally OK inside variable functions.
    |
    | If you have variables, the line has to be passed back to the variable
    | expansion, and if you haven't quoted or escaped the & it will be
    | treated as
    | a command separator.
    |
    | It's worked that way forever.

    This is one of the reasons I do not use the ampersand character & as the command separator. As Charles suggested, when literal & is needed, make sure it is not your command separator.
    --
    Steve
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,299
    Likes Received:
    39
    I see different-but-related issues when using | for logical OR in an expression containing expandables. It's probably safest to always use words instead of symbols wherever there's an overlap. (And perhaps the latter should be de-documented or deprecated?)
     

Share This Page