# Missing \<= 2 \<= 3 does not work

**URL:** <https://discourse.julialang.org/t/missing-2-3-does-not-work/88658>\
**Category:** General Usage\
**Created:** [October 13, 2022, 12:11pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658 "2022-10-13T12:11:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [October 13, 2022, 12:11pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/1 "2022-10-13T12:11:07Z")

</div>

```julia
julia> f() = missing <= 2 <= 3
f (generic function with 1 method)

julia> @code_lowered f()
CodeInfo(
1 ─ %1 = Main.missing <= 2
└── goto #3 if not %1
2 ─ %3 = 2 <= 3
└── return %3        
3 ─ return false
)

julia> f()
ERROR: TypeError: non-boolean (Missing) used in boolean contextStacktrace:
 [1] f() @ Main .\REPL[19]:1
 [2] top-level scope @ REPL[21]:1

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 13, 2022, 12:15pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/2 "2022-10-13T12:15:06Z")

</div>

[Chained comparisons](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Chaining-comparisons) “use the `&&` operator for scalar comparisons”. This means that your code is equivalent to something like:

```julia
missing <= 2 && 2 <= 3

```

which fails because the `&&` short-circuit operator cannot handle `missing`.

Just explicitly write it out and use `&`, ala `(missing <= 2) & (2 <= 3)`. Note that parentheses are needed because [`&` has higher precedence than `<=`](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity).

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 13, 2022, 12:18pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/5 "2022-10-13T12:18:52Z")

</div>

Of course… I’ve seen it, too much syntax lets me forget meaning.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [October 13, 2022, 12:21pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/6 "2022-10-13T12:21:07Z")

</div>

I see why it doesn’t work and how to prevent it. But shouldn’t we fix it? Seems inconsistent

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 13, 2022, 12:38pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/7 "2022-10-13T12:38:23Z")

</div>

> [@Impressium](#):
>
> But shouldn’t we fix it? Seems inconsistent

It seems like fixing it would require changing chained comparisons to use `&` instead of `&&`. This has been discussed previously in

> <https://github.com/JuliaLang/julia/issues/16088>
>
> It's harder to lower, more surprising and usually less efficient. We should just… lower \`a \< b \< c\` to \`(a \< b) & (b \< c)\`.

> <https://github.com/JuliaLang/julia/issues/39104>
>
> The following lowering makes it impossible to extend \`3 \<= x \<= 4\` for user-defi…ned types, e.g. in \[ModelingToolkit.jl\](https://github.com/SciML/ModelingToolkit.jl/):
> \`\`\`jl
> julia\> Meta.@lower 3 \<= x \<= 4
> :($(Expr(:thunk, CodeInfo(
> @ none within \`top-level scope'
> 1 ─ %1 = 3 \<= x
> └── goto #3 if not %1
> 2 ─ %3 = x \<= 4
> └── return %3
> 3 ─ return false
> ))))
> \`\`\`
> Could it be lowered to just \`3 \<=x && x \<= 4\` or similar?

and the conclusion by @jeff.bezanson in the latter issue was:

> Unfortunately I don’t see a non-breaking way to implement this.

which means it will have to wait until 2.0 (if ever)?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 13, 2022, 2:32pm UTC](https://discourse.julialang.org/t/missing-2-3-does-not-work/88658/8 "2022-10-13T14:32:10Z")

</div>

Can you file an issue at [MissingsAsFalse.jl](https://github.com/pdeffebach/MissingsAsFalse.jl)? Currently the `@mfalse` macro does not support this chained comparison, but it would be a good addition.
