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

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:

if a !in (b, c, d)

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

if !(a in (b, c, d))

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?


You could use ∉ = \notin <TAB>.


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?

This is an old debate, see e.g.

1 Like

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

julia> !in(2, 1:3)
1 Like

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.

Related github issue: ! for infix operators · Issue #25512 · JuliaLang/julia · GitHub

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>.

1 Like

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.