# 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:** 9\
**Page:** 3

<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, 10:17am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/41 "2024-02-22T10:17:35Z")

</div>

… and has always been, apparently. thanks for the reminder!

```julia
julia> VERSION
v"0.3.12"

julia> ∉
∉ (generic function with 1 method)

```

---

<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 22, 2024, 7:10pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/42 "2024-02-22T19:10:51Z")

</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. […] Would it be different for an infix operator?

I think it would. You can define tanpi, but that’s ok; since it’s not an operator. `notin` isn’t the best variable name, but you want it to still work if used. Assuming you couldn’t redefine, no more than:

```julia
julia> import Base.∉

julia> ∉ = 1
ERROR: cannot assign variable Base.∉ from module Main

```

---

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

</div>

> [@Tamas\_Papp](#):
>
> it is simple to type, and is conventional enough.

It just mixes very awkwardly with `in`. It would be so much narural with `!in`.

---

<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 22, 2024, 10:02pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/44 "2024-02-22T22:02:51Z")

</div>

> [@DNF](#):
>
> It just mixes very awkwardly with `in`. It would be so much narural with `!in`.

I agree it would be a good addition, but I prefer the style of `in` for iteration, `∈` for inclusion, `=` only for assignment, I saw that suggested somewhere as good style and happen to agree. That would mean that `∉` is only paired with `∈`, since `for !(i in iterator)` isn’t going to get you much of anything you want.

---

<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 22, 2024, 10:05pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/45 "2024-02-22T22:05:58Z")

</div>

> [@mnemnion](#):
>
> `=` only for assignment

Iteration _is_ assignment. Each time around the loop it assigns the loop variable.

---

<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 22, 2024, 10:07pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/46 "2024-02-22T22:07:39Z")

</div>

> [@jar1](#):
>
> Iteration _is_ assignment. Each time around the loop it assigns the loop variable.

I don’t disagree with what you’re saying, but did what I said actually strike you as unclear? It seems perfectly obvious what I mean, in context: assignment which isn’t a part of an iterated loop.

---

<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 22, 2024, 10:10pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/47 "2024-02-22T22:10:02Z")

</div>

It seems better to have one syntax for assignment. I don’t see the benefit of adding a special syntax for assignment specifically for one particular context when it behaves exactly the same as a normal assignment.

---

<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 22, 2024, 10:11pm UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/48 "2024-02-22T22:11:27Z")

</div>

> [@jar1](#):
>
> It seems better to have one syntax for assignment.

That ship sailed a long time ago.

> [@jar1](#):
>
> I don’t see the benefit of adding a special syntax for assignment specifically for one particular context when it behaves exactly the same as a normal assignment.

Great. I withdraw my plan to review your code and make you conform to my chosen style. It was a mistake to propose it in the first place.

---

<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 23, 2024, 7:01am UTC](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/49 "2024-02-23T07:01:17Z")

</div>

> [@Palli](#):
>
> ```julia
> julia> import Base.∉
> 
> julia> ∉ = 1
> ERROR: cannot assign variable Base.∉ from module Main
> 
> ```

I don’t understand your point. If you want to use `∉` as variable name, just don’t import the base version (and don’t refer to it)?

It’s the same with anything:

```julia
julia> import Base.tanpi

julia> tanpi = 1
ERROR: cannot assign a value to imported variable Main.tanpi

```

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