# Comparison parsing AST

**URL:** <https://discourse.julialang.org/t/comparison-parsing-ast/1672>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [January 24, 2017, 11:42pm UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672 "2017-01-24T23:42:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZacLN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacln/32/2748_2.png) [@ZacLN](https://discourse.julialang.org/u/ZacLN)\
**Post date:** [January 24, 2017, 11:42pm UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/1 "2017-01-24T23:42:25Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [January 25, 2017, 2:00am UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/2 "2017-01-25T02:00:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ZacLN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacln/32/2748_2.png) [@ZacLN](https://discourse.julialang.org/u/ZacLN)\
**Post date:** [January 25, 2017, 9:40am UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/3 "2017-01-25T09:40:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpiitula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpiitula/32/471_2.png) [@jpiitula](https://discourse.julialang.org/u/jpiitula)\
**Post date:** [January 25, 2017, 2:50pm UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/4 "2017-01-25T14:50:22Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![ZacLN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacln/32/2748_2.png) [@ZacLN](https://discourse.julialang.org/u/ZacLN)\
**Post date:** [January 25, 2017, 3:37pm UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/5 "2017-01-25T15:37:53Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jpiitula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpiitula/32/471_2.png) [@jpiitula](https://discourse.julialang.org/u/jpiitula)\
**Post date:** [January 25, 2017, 3:58pm UTC](https://discourse.julialang.org/t/comparison-parsing-ast/1672/6 "2017-01-25T15:58:45Z")

</div>

Choose whichever form is more _convenient_ to you.
