# Supporting syntax \`x not in y\` as alias for \`!(x in y)\`

**URL:** <https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146>\
**Category:** Internals & Design\
**Created:** [February 13, 2024, 11:01am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146 "2024-02-13T11:01:34Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [February 13, 2024, 7:54pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/21 "2024-02-13T19:54:43Z")

</div>

Please, notnotin, that’s nogood.🙏

---

<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:** [February 13, 2024, 8:36pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/22 "2024-02-13T20:36:29Z")

</div>

> [@DNF](#):
>
> Please, notnotin, that’s nogood

[Newspeak](https://en.wikipedia.org/wiki/Newspeak) FTW.

---

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [February 14, 2024, 3:46am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/23 "2024-02-14T03:46:21Z")

</div>

> [@fingolfin](#):
>
> one of the issues with the `!in` proposal – `!=` does _not_ mean `not =`

The solution is obvious: introduce `!n` and `!sa`.

---

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [February 14, 2024, 8:33am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/24 "2024-02-14T08:33:56Z")

</div>

What is `ComposedFunction` inherited the fixity of its inner function? That would make `!in` infix, but keep `!isdigit`, for example, prefix. Would that work? I know that fixity is something that’s decided at parse time, so obviously the parser needs to be modified to take care of this. But _semantically_, this would be easy to explain.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 14, 2024, 11:50am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/25 "2024-02-14T11:50:41Z")

</div>

> [@mnemnion](#):
>
> Actually, `isnta` is growing on me

How about `aint`? Ok, that was a joke (thought Julia could have been the first programming language with more diverse English [operator]): [Ain't - Wikipedia](https://en.wikipedia.org/wiki/Ain%27t)

> The use of _ain’t_ is a continuing subject of [controversy in English](https://en.wikipedia.org/wiki/Linguistic_prescription)

[and not\_aint, naint? !aint…?]

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [February 14, 2024, 12:42pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/26 "2024-02-14T12:42:22Z")

</div>

I considered `ainta`, but then thought, no, jokes like that wear old after a while (e.g. `eye`, `who`, …).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 14, 2024, 12:55pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/27 "2024-02-14T12:55:17Z")

</div>

> [@stevengj](#):
>
> just allow `!in` and `!isa`, which seem like the least-objectionable and the most-beneficial infix operators to negate. I don’t see much of a need for `!<` or `!!` or `!:<`.

They may be the least objectionable, but this does not mean that it is worth introducing special cases for them either.

Ideally, surface syntax is a few general rules that compose well, with the minimum number of special cases. The fact that a special case is not very objectionable or is minimally beneficial is not enough to justify it, the bar should be much higher.

---

<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:** [February 14, 2024, 2:31pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/28 "2024-02-14T14:31:38Z")

</div>

The objectional part is actually, imo, that `a !<op> b` doesn’t work, while `!<op>(a, b)` does. Even though it’s hard to make this work for every case (due to `!=` et al), I think special-casing `!in` and `!isa` would provide a better 'illusion of consistency than the status quo.

---

<div class="post-metadata">

**Author:** ![mnemnion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mnemnion/32/206596_2.png) [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Post date:** [February 14, 2024, 3:58pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/29 "2024-02-14T15:58:03Z")

</div>

> [@Palli](#):
>
> How about `aint`?

`if aInt aint Int` this aint int, chief.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [February 16, 2024, 2:36am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/30 "2024-02-16T02:36:27Z")

</div>

> [@fingolfin](#):
>
> I don’t view `in` as syntactic sugar for `=`

You are wrong:

```julia
julia> :( for i in itr end )
:(for i = itr
      #= REPL[1]:1 =#
      #= REPL[1]:1 =#
  end)

julia> :( (x for x in itr) )
:((x for x = itr))

```

(sorry, I’m sure this isn’t what you meant 😉 )

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 16, 2024, 6:02am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/31 "2024-02-16T06:02:18Z")

</div>

Fans of infix composition might be interested in

> <https://github.com/JuliaLang/julia/issues/53324>
>
> I use the \`∘\` composition operator often. There are two simplest generalization…s of that operator to more data arguments \`xs\`: 
> 
> \`\`\`jl
> "g takes multiple arguments; f takes one."
> (xs...) -\> f(g(xs...))
> "g takes one argument; f takes multiple."
> (xs...) -\> f((g(x) for x in xs)...)
> \`\`\`
> 
> For example, to find the max of the absolute value of each argument, the syntax would be \`-1 ∨⊚↑ -2\` where
> 
> \`\`\`jl
> ⊚(f,g) = (xs...) -\> f((g(x) for x in xs)...); # g takes one argument; f takes multiple.
> ∨(x...) = max(x...); # Generalization of logical\_or.
> ↑(x) = abs(x)
> 
> \-1 ∨⊚↑ -2 # 2
> \`\`\`
> 
> Currently we have:
> 
> \`\`\`jl
> julia\> ((∨)⊚↑)(-1, -2)
> 2
> \`\`\`
> 
> But there are problems:
> 
> 1. \`(∨)\` requires parentheses, which is annoying. This could be solved by adding a precedence rule for designated combinator operators like \`⊚\`.
> 
> 2. Infix doesn't work: \`-1 (∨)⊚↑ -2\` is a \`ParseError\`. This could be solved by letting combinator expressions be infix.
> 
> 3. Prefix \`((∨)⊚↑)\` is wrapped in parentheses. This seems least likely to change, but not so bad.
> 
> In this issue I'm not asking for the actual operators to be defined, just the syntax support so I can try to put the operators in a package like CompositionsBase.jl where \`f⨟g = g∘f\` is.

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [February 17, 2024, 12:53am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/32 "2024-02-17T00:53:05Z")

</div>

Note that adding new alphabetic operators is not something we can add in 1.x because it breaks code that might already have identifiers with those names. eg, I might have a variable called `notin`, so adding an operator called `notin` would break my code.

I personally like the unicode operators. There are many unicode infix operators that do not have non-unicode alternatives, so it’s best to get used to using them. eg: `\subseteq` ⊆, `\nsubseteq` ⊈, `\subsetneq` ⊊, `\supseteq` ⊇, `\approx` ≈, `\napprox` ≉

---

<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:** [February 17, 2024, 8:05am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/33 "2024-02-17T08:05:49Z")

</div>

That’s not a problem for `!in`, though.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 17, 2024, 8:28am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/34 "2024-02-17T08:28:32Z")

</div>

An infix operator like `∈` in `y !∘∈ xs` could be allowed without problem, and I think `1 !∘∈ [3,4]` is good syntax.

Edit: this isn’t actually what I meant. I’ll try again later.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 17, 2024, 8:34am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/35 "2024-02-17T08:34:43Z")

</div>

> [@bluesmoon](#):
>
> I might have a variable called `notin`, so adding an operator called `notin` would break my code

I’m not sure that’s right… For example Julia 1.10 has the new `tanpi` function. This doesn’t break code that used `tanpi` as variable name: if you define `tanpi` before using the `tanpi` function, your definition takes precedence. Would it be different for an infix operator?

---

<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:** [February 17, 2024, 9:56am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/36 "2024-02-17T09:56:48Z")

</div>

> [@jar1](#):
>
> I think `1 !∘∈ [3,4]` is good syntax.

That’s pretty obscure and confusing. It’s also a mishmash of a set operator a logical operator (in programming notation), and a function composition operator. Just to express a set operation. They don’t blend well, imo. I think this requires too broad knowledge to understand, in addition to being quite messy.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 17, 2024, 10:00am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/37 "2024-02-17T10:00:00Z")

</div>

Also who would want to write `1 !∘∈ [3,4]` instead of `1 ∉ [3,4]`?

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [February 21, 2024, 3:34am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/38 "2024-02-21T03:34:24Z")

</div>

> [@sijo](#):
>
> > [@bluesmoon](#):
> >
> > I might have a variable called `notin`, so adding an operator called `notin` would break my code
> 
> I’m not sure that’s right… For example Julia 1.10 has the new `tanpi` function. This doesn’t break code that used `tanpi` as variable name: if you define `tanpi` before using the `tanpi` function, your definition takes precedence. Would it be different for an infix operator?

Since `notin` would have a mechanism very similar to `in` and

```julia-repl
julia> function in(x,y)
       5
       end
in (generic function with 1 method)

julia> 7 in [8,9]
5

julia> in("a","b")
5

julia> 

```

You are probably right (which actually surprised me as well).

Edit: I do still prefer `!in` or only supporting the Unicode variant

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 22, 2024, 9:57am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/39 "2024-02-22T09:57:30Z")

</div>

> [@sijo](#):
>
> Also who would want to write `1 !∘∈ [3,4]` instead of `1 ∉ [3,4]`?

If the actual problem proposed by this topic is “having a more compact way of writing `!(x in y)`”, then I think that simply defining and exporting `∉` with the semantics above is the best solution. We have the Unicode symbol, it is simple to type, and is conventional enough.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 22, 2024, 10:05am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/40 "2024-02-22T10:05:49Z")

</div>

It’s already defined and exported 🙂

[Previous page](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146.md?page=1)

[Next page](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146.md?page=3)
