March 7, 2023, 9:44am
I have encountered the absence of an
!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
∈ or are there other reasons?
You could use
∉ = \notin <TAB>.
March 7, 2023, 10:12am
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
March 7, 2023, 10:19am
This is an old debate, see e.g.
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…
There’s the functional form that you may use, rather than a binary operator:
julia> !in(2, 1:3)
March 7, 2023, 11:10am
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.
March 7, 2023, 11:48am
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
!=. (And the same with
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
March 7, 2023, 4:51pm
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.