-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add some unicode function synonyms and infix operators #6582
Conversation
Some other useful ones:
|
@jiahao if you do use |
Oh, does Distributions use √ already? |
In some of the constants, but they could easily be renamed. |
I think the constants are fine. You'd have to write |
- Strict subsets ⊂, ⊊ - Negated synonyms ⊈, ⊄
The √ operator should be made to behave like the minus sign (but with different precedence probably) – unary prefix and binary infix – at which point it will break that code. |
Beware of the mismatch between △, which is used to denote symmetric difference of sets, and setdiff. Setminus would be a more appropriate name for the function setdiff. Also one could add a symdiff function to base and associate it to △. math> {1,2,3}△{3,4,5} = {1,2,4,5} |
Yeah, I would agree on △: it's used for too many other things to make it standard (also, it would probably cause issues if we try to normalise, as its also the greek capital delta) |
The commit message is wrong; I had set △ as Also (thank goodness), not even NFKC wants to normalize the upright white triangle to the Greek Delta. julia> normalize_string("△", :NFKC) == normalize_string("Δ", :NFKC)
false |
Ah, I see. I guess the other problem is that it's not a unicode math operator: it's actually under geometric shapes |
Ah, symdiff exists, I didn't know it has been implemented. Nice. Note that there are other unicode characters that look like a triangle. |
@simonbyrne Yes, I cheated. :) |
…≥ (.>=), .≤ (<=), .≠ (.!=)
Is (.//) defined anywhere?
Done with laundry so I'm going to stop here for now. Happy 🚲🏠ing ⌂ |
⊂ and ⊄ seem useful to have around for user-defined relations, but otoh it seems odd to define infix operators that are never used in Base.
My feeling is that any Unicode codepoint from category Sm whose documented meaning and/or only common interpretation is as an infix operator (e.g. The only question would be precedence, but nearly all such operators have clear analogies to existing operators (e.g. |
Eventually supporting all Unicode-representable infix operators could be something worth doing, but it's a bit too much to type in manually. Also, as @JeffBezanson points out, having hundreds of operators means that the parser will have to be rewritten to be cleverer at identifying them beyond the current linear search method. |
If you look at category Sm, most of the symbols are not unambiguously infix; there's probably a couple hundred unambiguous infix operators at most, and this is practical to type manually. It's pretty essential to go through them manually, actually, in order to intelligently categorize them. But I agree that we would need to switch to (e.g.) a hash table instead of linear search. |
So, about that UROP student... |
(|\|>| |<\||) | ||
(: |..|) | ||
(+ - |.+| |.-| |\|| $) | ||
(+ - |.+| |.-| |\|| $ ∩ ∪ △) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't ∩ have the precedence of &
and ∪
have the precedence of |
?
@jiahao, I made a quick pass through category Sm, and here are the symbols that seemed (a) unambiguously infix and (b) had a clear analogy to existing operators so that the precedence is clear:
We also might consider treating some of the arrows as infix operators, since that is how they seem to be used in practice, although the precedence is less clear: left/right arrows (precedence of combination of comparisons and left-right arrows: ⥱⥲⥳⥴⥵⥶⥷⥸⥹⥺⥻ up/down arrows (precedence of …probably also ⇈⇊, although these are in category So rather than category Sm, and we might want to support other arrows in category So as infix operators too. I probably missed some, but we can always add more later. |
@StefanKarpinski It would be nice to have some sort of inbuilt infix operator for |
@simonbyrne, I'm skeptical of using arrows for this. If we need infix minimum and maximum, I would just make |
having the up/down arrows be in the equivalence class of Also ∩ ∈ [&] and ∪ ∈ [|] make sense. |
@JeffBezanson, does femtolisp have a hash-table implementation (or some other easy way to circumvent the performance problems of supporting lots of Unicode infix operators)? |
+1 |
Yes, there is a hash table. |
Merging this for now, as I believe it covers all the uncontroversial cases. |
RFC: Add some unicode function synonyms and infix operators
I'm removing |
Also |
Closes #552.