Search code examples
language-designshort-circuiting

Are there any right associative short-circuit operators


I'm working on a interrupter the lets one define their own operators. The goal then is to take an AST that looks like exp op exp op exp and turn it into either exp op (exp op exp) or (exp op exp) op exp based on the relative precedence and associativity of the two operators. The language is dynamic so the only way to know what version of the operator to use is to evaluate the first expression and ask it what version of op to use.

On the other hand, it is important that we not evaluate the second expression because if op is || (as commonly used) then we should be able to short-circuit if the first exp is false.

a problem would arise if some operator were both right associative and short-circuiting. My question is are there any right associative, short-circuiting operators in common use (for a chosen value of "common")?

N.b. assignment is handled separately by the parser so = is not an operator and a (op)= b is syntactic sugar for a = a op b.


Solution

  • Boolean implication might be.

    I would probably read

    a → b → c
    

    as "a implies that b implies c" which would suggest that it should parenthesize

    a → (b → c)
    

    and boolean implication should probably be short-circuiting since when a is false then the right side of (a → b) is irrelevant to the result.