- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
! for infix operators #25512
Comments
I generally like this idea but there are some consistency issues. For example, if Side note: interesting tie-in with #25435. If we merge that then |
There might be a more general feature in this general area that would allow unary operators to operate on other operators, similar to adverbs in J. Reminds me a bit of Julia's vectorizing |
We could resolve that by adding a type-assert |
I suggested the same on the other thread, but it's a bit weird and arbitrary. |
Bumping this up after I spent 30 minutes yesterday trying to figure out the right way to do "not in" and realized the best way right now is to do |
Have you considered ∉ (\notin)? This is one case where I prefer using unicode operators. (In fact, I use ∈ to test for inclusion and "in" for for loops and generators, so the ∉ operator comes perfectly natural to me.) |
You don't have the equivalent of ∉ for other infix ops. For example |
You can always define your own infix operators as aliases: julia> ⊲ = <: # \varlefttriangle
<: (built-in function)
julia> ⋪ = !<: # \ntriangleleft
#76 (generic function with 1 method)
julia> ⊢ = isa # \vdash
isa (built-in function)
julia> ⊬ = !isa # \nvdash
#76 (generic function with 1 method)
julia> 1 ⊢ Int
true
julia 1.0 ⊬ Int
true I appreciate that these would not be generally recognized, or that this is not something that easily generalizes to all infix operators, but it works if that's what you are looking for. |
We could also just add special-case parsing for |
It would be nice to be able to negate infix operators by writing
and have that be equivalent to
This is analogous to how
!<function>
works, and it also works for operators called in function form, like this:Also allowing infix negation seems more consistent.
Related discussion is here
Many unicode operators have negated versions, but not all. Furthermore, negated unicode operators frequently are rendered as small and hard to read compared to surrounding code. As for ascii operators, I miss in particular:
The unicode version of
!in
is∉
, but mixingin
and∉
in code isn't very pleasing to the eye. And having!
compose with arbitrary infix operators means that they will always work, instead of depending on whether or not a suitable negated unicode symbol happens to be available.The text was updated successfully, but these errors were encountered: