Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infix "!in" as synonym for ∉ ? #15353

Open
samoconnor opened this issue Mar 4, 2016 · 35 comments
Open

Add infix "!in" as synonym for ∉ ? #15353

samoconnor opened this issue Mar 4, 2016 · 35 comments
Labels
needs decision A decision on this change is needed

Comments

@samoconnor
Copy link
Contributor

I miss not having infix ni as the opposite of in like Tcl has

is nice, but I don't know how to type that.

I end up with a lot of if !(x in v) ... which I'd rather replace with if x ni v ...
Does this seem crazy to people without a Tcl disorder?

Update: waiting for general infix ! per #15353 (comment) .

@samoconnor samoconnor changed the title Add Add "ni∉ Mar 4, 2016
@nalimilan
Copy link
Member

?

@samoconnor samoconnor changed the title Add "ni∉ Add "ni" as synonym for ∉ ? (opposite of "in") Mar 4, 2016
@samoconnor
Copy link
Contributor Author

Sorry @nalimilan I think I pressed enter too soon an submitted a half-typed issue.

@Dawny33
Copy link

Dawny33 commented Mar 4, 2016

can be typed by \notin (both in Atom with the latex plugin and the REPL)

@samoconnor
Copy link
Contributor Author

HI @Dawny33, I'm not sure what Atom is. I mostly only ever type code into Vim. I'm sure there is a way to type in Vim, but I can only fit a finite number of Vim shortcuts in my brain.

I think it's reasonable to expect that non-ascii operators have an ascii-typeable equivalent.

@Dawny33
Copy link

Dawny33 commented Mar 4, 2016

@samoconnor Yeah, the request is quite reasonable 👍

Just trying to point out the latex shortcut for quick reference!

@nalimilan
Copy link
Member

Does this seem crazy to people without a Tcl disorder?

Yes, I must confess I'm in that camp. :-) Using if/fi and things like that always sounded weird to me. We may as well use out (just joking).

@samoconnor
Copy link
Contributor Author

ni is nice because it is reverse("in") and also "not in" and also because Ni!

But if ni is too cute 🐶, then !in or not in or notin would be fine too...

@tkelman
Copy link
Contributor

tkelman commented Mar 4, 2016

If we really need an ascii infix not-in operator (is !(a in b) not sufficient for most purposes?) then I'd rather have it spelled notin than ni.

@Dawny33
Copy link

Dawny33 commented Mar 4, 2016

@tkelman +1

notin plays well with the latex shortcut \notin, so it avoids unnecessary confusion. And yeah, we need a not in operator, as it is a bit of a frequent usage.

@KristofferC
Copy link
Member

Ni! Ni! Ni!

@samoconnor
Copy link
Contributor Author

@KristofferC Icky Icky Icky Ptang

@samoconnor samoconnor changed the title Add "ni" as synonym for ∉ ? (opposite of "in") Add infix "notin" as synonym for ∉ ? Mar 4, 2016
@nalimilan
Copy link
Member

Indeed, the movie reference is the only possible justification of Tcl's choice.

@samoconnor
Copy link
Contributor Author

Adding notin(x, itr) = !in(x,itr) to reduce.jl is easy enough.
What has to be changed to make it work as an infix operator?

@eschnett
Copy link
Contributor

eschnett commented Mar 4, 2016

Clearly, ni should be equivalent to \ni, which is-- the left-right swapped version ofin`.

@vchuravy
Copy link
Member

vchuravy commented Mar 4, 2016

@samoconnor You might want to look at https://github.com/JuliaLang/julia-vim AFAIK it can replace \notin with the appropriate unicode symbol

@StefanKarpinski
Copy link
Member

Perhaps parsing !in as infix would be better, as in a !in b.

@kmsquire
Copy link
Member

kmsquire commented Mar 4, 2016

+1 for !in as an infix operator.

@JeffBezanson
Copy link
Member

One reason to prefer notin is that it's compatible with allowing all functions to use infix syntax, while !in would continue to be a special case even if we made that change.

@StefanKarpinski
Copy link
Member

If a foo b desugars to foo(a,b) then a !foo b could generically desugar to !foo(a,b). On the other hand, I find this particular syntax issue to be mild enough that it can wait.

@nalimilan
Copy link
Member

Could be useful, but we'll have to wait until more infix operators are supported to really give !in that general meaning. Until then, it will only be a weird exception.

@vtjnash vtjnash added the needs decision A decision on this change is needed label Mar 8, 2016
@samoconnor
Copy link
Contributor Author

If it is agreed that a general infix ! and !in can wait, then notin seems to be broadly agreeable.
Would a PR for notin be welcome?

@StefanKarpinski
Copy link
Member

I'm against it because then we'd have to deprecate notin when !in happens. In the meantime, writing !(a in b) is not so awful.

@samoconnor samoconnor changed the title Add infix "notin" as synonym for ∉ ? Add infix "!in" as synonym for ∉ ? Mar 16, 2016
@samoconnor
Copy link
Contributor Author

Fair enough.

@KristofferC
Copy link
Member

Now have !in

@DNF2
Copy link

DNF2 commented Mar 23, 2019

Does it also solve #25512, or does it only work for in?

@nalimilan
Copy link
Member

But x !in y doesn't work, right? Yet that's what this issue is about.

@KristofferC
Copy link
Member

Yeah, sorry, I missed the actual point here.

@KristofferC KristofferC reopened this Mar 24, 2019
@Moelf
Copy link
Contributor

Moelf commented Aug 21, 2019

I think people are upset that you have to write !in(2, [2,3]) but can't write 2 !in [2,3]

@StefanKarpinski
Copy link
Member

Allowing ! before infix word operators (in, isa) seems like it would ok to me. However it's slightly dangerous territory since by analogy if a !in b means !(a in b) then one would expect that a !== b to mean !(a == b) but it actually means !(a === b).

@Moelf
Copy link
Contributor

Moelf commented Aug 21, 2019

maybe disallow !== say ambiguity error?

@yurivish
Copy link
Contributor

yurivish commented Aug 21, 2019

You also can't broadcast in in infix form, and I think it would be nice if you were able to do that.

julia> in.(1, [[1, 2], [3, 4]])
2-element BitArray{1}:
  true
 false

julia> 1 .∈ [[1, 2], [3, 4]]
2-element BitArray{1}:
  true
 false

julia> 1 .in [[1, 2], [3, 4]]
ERROR: syntax: space before "." not allowed in "1 ."

@StefanKarpinski
Copy link
Member

maybe disallow !== say ambiguity error?

Yeah, to hell with no breaking changes 😂

@Moelf
Copy link
Contributor

Moelf commented Aug 21, 2019

oh... right !== is already there sorry

@nvhoang3110
Copy link

nvhoang3110 commented Jun 15, 2022

Please is there any news regarding to the issue ? Some think like not in just like in Python would be nice.

@Moelf
Copy link
Contributor

Moelf commented Oct 16, 2024

I feel like the best we can do is special case notin as an infix thing, similar to isa, since it's very clear that general !<infix op> can't happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests