# Optimizations of \`and\` and \`or\` (possibly new semantics for) and comparison chaining

**URL:** <https://discourse.julialang.org/t/optimizations-of-and-and-or-possibly-new-semantics-for-and-comparison-chaining/1364>\
**Category:** Offtopic\
**Created:** [January 9, 2017, 11:17am UTC](https://discourse.julialang.org/t/optimizations-of-and-and-or-possibly-new-semantics-for-and-comparison-chaining/1364 "2017-01-09T11:17:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [January 9, 2017, 11:17am UTC](https://discourse.julialang.org/t/optimizations-of-and-and-or-possibly-new-semantics-for-and-comparison-chaining/1364/1 "2017-01-09T11:17:05Z")

</div>

A. Continuing the discussion from [Does Julia ever do outlining?](https://discourse.julialang.org/t/does-julia-ever-do-outlining/1354/6):

@giordano

> Nothing prevents you from testing the condition

> `1 < -3 < 4`

> in this case there is no performance gain, on the contrary you’ll have performed one extra test.

In that case, with constants no, but in general, could be. See may race idea of (long) chaining of || (converted from [implicit] &&) at:

> <https://github.com/JuliaLang/julia/issues/19933#issuecomment-271257127>
>
> What @Ismael-VC wants with https://github.com/JuliaLang/julia/pull/19788 are str…ict aliases. There are other options, the problem may not be with his code though.\*
> 
> If taken at face-value, left short-circuiting disallows running first the (or only) right-side:
> 
> \`\`\`
> if slow\_function!(x) && fast\_function!(y)
> takes\_a\_long\_time\_getting\_here
> else
> or\_takes\_a\_long\_time\_getting\_here
> end
> \`\`\`
> 
> I have some ideas to fix that, they may be strictly implementations details, NOT incompatible with left short-circuiting, but then you need lots of prove-work to show absence of "side-effects".
> 
> There are two options:
> \* Disallow calling functions with side-effects (braking change for && and || but not new operators).
> \* Ignoring side-effects!
> 
> if fun1!(x) and fun2!(x) # note x-es are repeated, not y as above
> 
> is even worse \[maybe the other if can work despite the !s \]
> 
> If we announce \`and\` and \`or\` not promising too much, maybe reusing his code (mostly; changes would be elsewhere, and in NEWS.md), then his code could possibly work.
> 
> I want to allow running, either side, or both (as &), or even neither (yes, that's a possibility..). And running both sides at once in separate thread, possibly killing them half-way through.
> 
> \* I'm unclear on:
> 
> \`(define is-prec-comparison?
> (augment-prec-with-infix prec-comparison 'in 'isa))
> 
> \[..\]
> 
> (put! prec-table 'in (get prec-table '== 0)) ; add \`in\` to the prec-table
> (put! prec-table 'isa (get prec-table '== 0)) ; add \`isa\` to the prec-table\`

B. @ihnorton You merged into the outlining (and closed it! EDIT: I see the “no” now…). I guess I was a little off-topic at the other thread you merged from. The outlining question wasn’t closed, so I guess you may have made a mistake on closing (who has the priv. to undo?)?

Didn’t you also merge into the wrong thread…?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [January 9, 2017, 2:21pm UTC](https://discourse.julialang.org/t/optimizations-of-and-and-or-possibly-new-semantics-for-and-comparison-chaining/1364/2 "2017-01-09T14:21:36Z")

</div>

2 posts were merged into an existing topic: [Does Julia ever do outlining?](https://discourse.julialang.org/t/does-julia-ever-do-outlining/1354)

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [January 9, 2017, 2:21pm UTC](https://discourse.julialang.org/t/optimizations-of-and-and-or-possibly-new-semantics-for-and-comparison-chaining/1364/3 "2017-01-09T14:21:36Z")

</div>


