# Why isn't there a \`!in\` or \`!∈\` function/operator?

**URL:** <https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654>\
**Category:** General Usage\
**Created:** [March 7, 2023, 9:44am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654 "2023-03-07T09:44:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [March 7, 2023, 9:44am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/1 "2023-03-07T09:44:06Z")

</div>

I have encountered the absence of an `!∈` or `!in` operator many times now and my muscle memory insists on telling me that it should exist:

```julia
if a !in (b, c, d)
  ...
end

```

Why isn’t there an analogous operator/function for this very idiomatic construct? IMHO, it is much, much clearer to understand and process than writing

```julia
if !(a in (b, c, d))
  ...
end

```

and intuitively it wouldn’t be slower either. Was this a conscious decision to not have the negation of `in`/`∈` or are there other reasons?

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [March 7, 2023, 9:46am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/2 "2023-03-07T09:46:50Z")

</div>

You could use `∉ = \notin <TAB>`.

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [March 7, 2023, 10:12am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/3 "2023-03-07T10:12:50Z")

</div>

Ah, I didn’t know about that! Good point, but isn’t there anything for people who cannot use non-ASCII characters? It seems weird that there is an imbalance with `∉` existing but `!in` not?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 7, 2023, 10:19am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/4 "2023-03-07T10:19:31Z")

</div>

This is an old debate, see e.g.

> [@Non-unicode versions of unicode functions in base/stdlib?](https://discourse.julialang.org/t/non-unicode-versions-of-unicode-functions-in-base-stdlib/13401):
>
> I’m looking at someone else’s code in Julia 1.0 and noticed they use the ∉ (not in) function, which doesn’t seem to have an ascii equivalent (e.g. notin). I realize that it’s possible to get the same functionality by typing ! (el in set), but it reminds me of the deprecation of @test\_approx\_eq in Julia 0.5 in favor of @test a ≈ b atol=ε in Julia 0.6. I have to say that I’m a little alarmed at the existence of unicode-only functions in base. I’ve seen people raise similar concerns in various pla…

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [March 7, 2023, 11:07am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/5 "2023-03-07T11:07:56Z")

</div>

There’s the functional form that you may use, rather than a binary operator:

```julia
julia> !in(2, 1:3)
false

```

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [March 7, 2023, 11:10am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/6 "2023-03-07T11:10:11Z")

</div>

> [@jishnub](#):
>
> There’s the functional form that you may use, rather than a binary operator:

True, but this is still a lot less legible than `!in` and doesn’t really explain why there is this asymmetry in the first place.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 7, 2023, 11:48am UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/7 "2023-03-07T11:48:09Z")

</div>

Related github issue: [! for infix operators · Issue #25512 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/25512)

One of the main problems mentioned in that issue is that the negated version of `==` isn’t `!==`, but `!=`. (And the same with `===` vs `!==`)

Aside from that, it would probably be possible to just let `a !<op> b` be the same as `!(a <op> b)` for any infix operator `<op>`.

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [March 7, 2023, 4:51pm UTC](https://discourse.julialang.org/t/why-isnt-there-a-in-or-function-operator/95654/8 "2023-03-07T16:51:46Z")

</div>

I agree that there is merit in finding a general solution. However, I think `in` is somewhat special as there already exists a non-ASCII equivalent, so to me it is not understandable why `!in` is not treated the same way.
