# Julia's infix as synonym for ∉ operator?

**URL:** https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846
**Category:** New to Julia
**Tags:** question, infix
**Created:** [June 15, 2022, 10:34pm UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846 "2022-06-15T22:34:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)
#### Post date: [June 15, 2022, 10:34pm UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/1 "2022-06-15T22:34:08Z")

</div>

Hello everyone.

I think there’s somebody raising the question in the past but since there’s no news or recent development then, I would like to talk about it again.

Julia has the infix operator `in` and its equivalence `∈`. The language also support the reverse, which is `∉`, but by my understanding, there’s no such thing as `!in` or `not in` like in Python.

Of course, I would happy to use `!(a in b)` in my code, but I think it’s reasonable to expect the non-ascii operators have an ascii-typeable equivalent. Plus, not everybody is happy using `∈` or `∉` in their code, so an infix operator to pair with `in` is reasonable idea.

Please let me know what do you think about this issue, and is there any new development regarded to it. Thank you in advance !

---

<div class="post-metadata">

### Author: ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)
#### Post date: [June 15, 2022, 10:43pm UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/2 "2022-06-15T22:43:07Z")

</div>

I don’t think there is much want for an infix ascii `\notin`. Julia allows you to pick your favourite of two “styles”,

- traditional ascii, `!(a in b)`; or
- mathematical `a ∉ b`,

and that’s good enough for most people. It seems like your proposal falls in between these two styles. Personally, I’d encourage going the whole way and just using ∉. Remember it’s ascii-typaple with `\notin<tab>`.

---

<div class="post-metadata">

### Author: ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)
#### Post date: [June 15, 2022, 11:57pm UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/4 "2022-06-15T23:57:57Z")

</div>

Thanks for replying. Yes, of course I know how to type and use Unicode inputs by using `\` and `<tab>` , but that doesn’t stop myself from asking why the language supports so many mathematics operators even like `∋` or `∌` but not a simple negation infix to pair with `in` . Please don’t get me wrong, I’ll happy to keep using `!(a in b)` and also `∉` in my code, but in the meantime, it’s a question about the language’s design that got me thinking time to time.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [June 16, 2022, 7:32am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/5 "2022-06-16T07:32:23Z")

</div>

> [@nvhoang.3110](#):
>
> but not a simple negation infix to pair with `in`

Because that’d require having a new reserved keyword in the parser, for limited benefits. The ASCII version of logical negotiation (`!`) has always been there and it’s not going anywhere.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [June 16, 2022, 7:56am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/6 "2022-06-16T07:56:24Z")

</div>

I suppose a Julian version of `not in` would be `!in`. That doesn’t work, but when typed before another method, it seems to make a method that can’t be called? What even is going on here:

```julia
julia> 3 in [3]
true
julia> 3 !in [3]
ERROR: syntax: extra token "!" after end of expression

julia> in
in (generic function with 35 methods)
julia> !in
#84 (generic function with 1 method)

julia> !+
#84 (generic function with 1 method)
julia> !+(1,1)
ERROR: MethodError: no method matching !(::Int64)

julia> !println
#84 (generic function with 1 method)
julia> (!println)("huh?")
huh?
ERROR: MethodError: no method matching !(::Nothing)

```

---

<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: [June 16, 2022, 8:05am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/7 "2022-06-16T08:05:46Z")

</div>

> [@Benny](#):
>
> it seems to make a method that can’t be called? What even is going on here:

```julia
!(f::Function) = (x...)->!f(x...)

julia> !in([1,2,3], 4)
true

```

It may be called as a normal function, just not as an infix.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [June 16, 2022, 8:25am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/8 "2022-06-16T08:25:54Z")

</div>

Seems like `!in([1,2,3], 4)` still parses as `in` then `!` separately. Parentheses can help call the actual `!in`:

```julia
julia> @which !in([1,2,3], 4)
!(x::Bool) in Base at bool.jl:35

julia> @which (!in)([1,2,3], 4)
(::Base.var"#84#85")(x...) in Base at operators.jl:1117

```

So I suppose the intention is to create methods to apply later, like `map(!in, args...)`, without having to write the whole `(x...)->!in(x...)`.

Would it be a breaking change to allow infix syntax for this, you know, parse `3 !in [4]` as `(!in)(3, [4])` or even just `!in(3, [4])`? Wouldn’t need to register a bunch of new `!_` operators, just parse our way to the `!(f::Function)` method we already got.

---

<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: [June 16, 2022, 9:15am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/9 "2022-06-16T09:15:18Z")

</div>

> [@Jollywatt](#):
>
> I don’t think there is much want for an infix ascii `\notin`

Well, _I_ certainly disagree with that statement: [! for infix operators · Issue #25512 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/25512) (and the request received some support.)

I would very much like to be able to write `a !in B`, but there are some problems with generalizing it, due to `!==` not being the negation of `==`.

---

<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: [June 16, 2022, 9:20am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/10 "2022-06-16T09:20:47Z")

</div>

More discussion here: [! for infix operators](https://discourse.julialang.org/t/for-infix-operators/8257) and [Add infix "!in" as synonym for ∉ ? · Issue #15353 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/15353)

---

<div class="post-metadata">

### Author: ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)
#### Post date: [June 16, 2022, 10:58am UTC](https://discourse.julialang.org/t/julias-infix-as-synonym-for-operator/82846/11 "2022-06-16T10:58:38Z")

</div>

Thanks for replying. Then I would agree with what @Benny and @jishnub said, as the version of `not in` should be `!in`, but it just doesn’t work like that. By adding the parenthesis, it becomes a normal function, not an infix anymore.
