julia icon indicating copy to clipboard operation
julia copied to clipboard

Add infix "!in" as synonym for ∉ ?

Open samoconnor opened this issue 9 years ago • 35 comments

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 https://github.com/JuliaLang/julia/issues/15353#issuecomment-192480765 .

samoconnor avatar Mar 04 '16 08:03 samoconnor

?

nalimilan avatar Mar 04 '16 08:03 nalimilan

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

samoconnor avatar Mar 04 '16 09:03 samoconnor

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

Dawny33 avatar Mar 04 '16 09:03 Dawny33

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.

samoconnor avatar Mar 04 '16 09:03 samoconnor

@samoconnor Yeah, the request is quite reasonable :+1:

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

Dawny33 avatar Mar 04 '16 09:03 Dawny33

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).

nalimilan avatar Mar 04 '16 09:03 nalimilan

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...

samoconnor avatar Mar 04 '16 10:03 samoconnor

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.

tkelman avatar Mar 04 '16 10:03 tkelman

@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.

Dawny33 avatar Mar 04 '16 10:03 Dawny33

Ni! Ni! Ni!

KristofferC avatar Mar 04 '16 10:03 KristofferC

@KristofferC Icky Icky Icky Ptang

samoconnor avatar Mar 04 '16 10:03 samoconnor

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

nalimilan avatar Mar 04 '16 10:03 nalimilan

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?

samoconnor avatar Mar 04 '16 10:03 samoconnor

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

eschnett avatar Mar 04 '16 13:03 eschnett

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

vchuravy avatar Mar 04 '16 14:03 vchuravy

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

StefanKarpinski avatar Mar 04 '16 17:03 StefanKarpinski

+1 for !in as an infix operator.

kmsquire avatar Mar 04 '16 18:03 kmsquire

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.

JeffBezanson avatar Mar 04 '16 19:03 JeffBezanson

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.

StefanKarpinski avatar Mar 04 '16 21:03 StefanKarpinski

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.

nalimilan avatar Mar 04 '16 21:03 nalimilan

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?

samoconnor avatar Mar 16 '16 00:03 samoconnor

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.

StefanKarpinski avatar Mar 16 '16 01:03 StefanKarpinski

Fair enough.

samoconnor avatar Mar 16 '16 01:03 samoconnor

Now have !in

KristofferC avatar Mar 23 '19 12:03 KristofferC

Does it also solve https://github.com/JuliaLang/julia/issues/25512, or does it only work for in?

DNF2 avatar Mar 23 '19 18:03 DNF2

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

nalimilan avatar Mar 24 '19 13:03 nalimilan

Yeah, sorry, I missed the actual point here.

KristofferC avatar Mar 24 '19 18:03 KristofferC

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

Moelf avatar Aug 21 '19 21:08 Moelf

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).

StefanKarpinski avatar Aug 21 '19 21:08 StefanKarpinski

maybe disallow !== say ambiguity error?

Moelf avatar Aug 21 '19 21:08 Moelf