-
-
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
Use \mapsto
( ↦ ) for anonymous functions
#11223
Comments
+1 |
If you want to try it out diff --git a/src/julia-parser.scm b/src/julia-parser.scm
index 36981c0..b4a1423 100644
--- a/src/julia-parser.scm
+++ b/src/julia-parser.scm
@@ -64,7 +64,7 @@
; operators that are special forms, not function names
(define syntactic-operators
'(= := += -= *= /= //= .//= .*= ./= |\\=| |.\\=| ^= .^= ÷= .÷= %= .%= |\|=| &= $= =>
- <<= >>= >>>= -> --> |\|\|| && |.| ... |.+=| |.-=|))
+ <<= >>= >>>= -> ↦ --> |\|\|| && |.| ... |.+=| |.-=|))
(define syntactic-unary-operators '($ & |::|))
(define syntactic-op? (Set syntactic-operators))
@@ -74,7 +74,7 @@
(define ctrans-op (string->symbol "'"))
(define vararg-op (string->symbol "..."))
-(define operators (list* '~ '! '¬ '-> '√ '∛ '∜ ctrans-op trans-op vararg-op
+(define operators (list* '~ '! '¬ '-> '↦ '√ '∛ '∜ ctrans-op trans-op vararg-op
(delete-duplicates
(apply append (map eval prec-names)))))
@@ -897,7 +897,7 @@
(case t
((|::|) (take-token s)
(loop (list t ex (parse-call s))))
- ((->) (take-token s)
+ ((-> ↦) (take-token s)
;; -> is unusual: it binds tightly on the left and
;; loosely on the right.
(let ((lno (line-number-filename-node s))) |
Would it need to be removed from prec-arrow? |
Yes, it should be if this were the a formal PR. But -1 on this proposal, I don't like the use of unicode for special forms that have a perfectly sane ascii equivalent. |
Similar to #8487 |
@jakebolewski Great, thanks for the code sample. I see where you're coming from, but it seems to me that basically all unicode would be excluded by your reasoning, e.g. using α ( From my point of view, one of the points of allowing unicode is that code can resemble hand-written (or LaTeX) equations as much as possible. |
+1. It seems like there is no other sane meaning for |
One difference is that it's a special form, so can't be handled with a simple alias. |
One counter-proposal: it might be useful to parse |
👍 That's a cool use of the Unicode character! |
+1 |
I really don't think we should make an operator for something that is a stopgap for something that just ought to be fixed. |
Reminds me of the macro-parsing of |
Yes, I like @stevengj's idea of allowing a few infix operators as macros, although I'm not sure if A bit unrelated: I'd really like to use |
The reason I suggested a macro for |
It would look less confusing to me to have |
object~method(x, y) Of course, I could write this as @call object.method(x, y) but if you're using the system a lot this adds a ton of noise to the code. It's really nice to have an escape hatch here. I agree that it wouldn't be right to make this work specifically for FastAnonymous, but as @stevengj says this could have plenty of uses for function-like things (Reactive.jl, function-like operators, etc.). |
I was noting that |
@one-more-minute I'm not convinced. In addition to macro-operators being poorly composable due to the lack of namespacing, there's already a quite straightforward escape hatch for dsl's to cut down on macro-call noise: @dsl begin
# anything you want
end |
Julia's support of Latex notation for unicode makes it really easy to create mathematical DSLs that look and feel like the mathematics we are used to writing. I'm making liberal use of them as operators (\otimes, \circ) myself. However, every time a symbol is reserved in the base language, the ability to do this is diminished. Keep in mind that the same symbol, however standard it may seem to be, ends up used differently in different subfields of math, physics, economics, and so on where Julia may be used. For a non-unicode example, I had to rewrite a lot of code when capital I became UniformScaling, since I was using it to mean the monoidal identity in a monoidal category, where that use is also standard. Another consideration is that unicode support is still buggy in many places (e.g. the red boxes in saved IJulia notebooks). For example, the default system font in Ubuntu 15.04 causes unicode characters to behave incorrectly (spacing issues causing illegibility or huge spaces) in the Julia terminal and in emacs until the font settings are changed. You gave us unicode and you can take it away, but let me plead for extreme caution in reserving things. |
I'll ask this here, as I did not right away find any other appropriate issue and I guess several of the Unicode & Julia experts are subscribed to this issue. I didn't want to open a new issue right away for something so small. It's great that So all of these work, in an expression: :(a ↦ b)
:(a → b)
:(a ← b) but this one
Any reason why this is so? |
|
This just came up again on Slack. Maybe it's time to reconsider this? |
+1.
|
I'm going to reopen this as there still seems to be broad interest, and there's no recorded reason for why it was closed. |
I think Jake just decided that he didn't like it. |
I can think of several points against this:
|
I didn't find #11223 (comment) super convincing but you've got some good points. The mathematician in me really wants this to work so I'm torn. I'll admit that personally I don't even use |
Cascadia code will also do the substitutions that |
I want to resurrect this, as every time I type |
I feel like there is a broad consensus of the core devs against this… |
It would be nice to be able to use the correct mathematical notation " ↦ " (
\mapsto
) for anonymous functions,x ↦ f(x)
, in addition tox -> f(x)
This sounds like it should be a relatively easy addition to the parser (but I don't know where to start).
The text was updated successfully, but these errors were encountered: