Comparison parsing AST

Is there any reason for the two AST forms for comparisons?
Expr(:call,:<, :a, :b) and Expr(:comparison, :a, :<, :b)both seem to generate the same code though the latter form only get’s generated in expressions with multiple comparisons, e.g. a<b<c

1 Like

I believe the difference is related to the short-circuiting behavior of the latter. Where the expression head :call will never cause short-circuiting, while :comparison will do so.

Can you think of an example where parsing to the latter syntax rather than the first would change behaviour or the resulting code? I don’t understand how short-circuiting would occur in the two argument case but am definitely missing something here

I think there’s just no reason to reject either form. Extra work for no gain at best, and likely to annoy someone who then would have to do the extra work to generate only the approved alternative even though both are correct.

And that someone might well be the compiler writer themselves :wink:

Ah OK, I’m coming to it from the opposite direction (writing a parser) where providing two forms of output makes things slightly more work!

Choose whichever form is more convenient to you.