-
-
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
support anglebracket ⟨ ⟩, floorbracket ⌊ ⌋, and ceilbracket ⌈ ⌉ #27697
base: master
Are you sure you want to change the base?
Conversation
I wonder if we should do something other than
and instead maybe something like
where |
src/julia-parser.scm
Outdated
@@ -2360,6 +2360,18 @@ | |||
((comprehension) `(braces ,@(cdr vex))) | |||
(else `(bracescat ,@(cdr vex)))))))) | |||
|
|||
((eqv? t #\⟨ ) | |||
(take-token s) | |||
`(call anglebracket ,@(parse-call-arglist s #\⟩))) |
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.
The way we'd usually do this is to parse it as (anglebracket ...)
, so that it can be distinguished from the user writing anglebracket(...)
. Then add a lowering rule in julia-syntax.scm to convert it to a call. See for example how vect
is handled.
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.
okay
I think the floor and ceiling brackets should just directly call I'm less sure what to do with angle brackets; do we want them to only ever mean dot product? |
Single-argument angle brackets |
src/julia-parser.scm
Outdated
@@ -159,7 +159,7 @@ | |||
(define reserved-word? (Set reserved-words)) | |||
|
|||
(define closing-token? | |||
(let ((closer? (Set '(else elseif catch finally #\, #\) #\] #\} #\;)))) | |||
(let ((closer? (Set '(else elseif catch finally #\, #\) #\] #\} #\⟩ #\⌋ #\⌉ #\;)))) |
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.
Doesn't this construct a Set
object every time closing-token?
is called? It seems like for performance we may want to define some global sets for this function.
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.
If you look closely, the let is outside the lambda.
@@ -905,3 +905,7 @@ julia> map(splat(+), zip(1:3,4:6)) | |||
``` | |||
""" | |||
splat(f) = args->f(args...) | |||
|
|||
anglebracket(x::Real, y::Real) = x * y |
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.
isn't this redundant with the dot
method? Shouldn't this be defined in the LinearAlgebra package only?
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.
Should we leave some sort of dummy definition in Base? My vague impression is, if there is no anglebracket
in Base, and PkgA and PkgB both defined and exported it, then there will be some kind of namespace clash? How to do it correctly?
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.
I think you can just do
function anglebracket end
which creates a function without any methods,
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.
Cool!
Another thing to think about is that it would be nice if this were designed in such a way to allow for bras and kets as discussed in https://discourse.julialang.org/t/a-qubit-dsl/8599/26 |
Would it make sense to make the functions the brackets get lowered to undefined by default, so that e.g. |
For instance, some may want |
I agree, I think we should put in place a way to parse them and leave it at that for now, as we've done with many other Unicode symbols. Meaning can be added later or can be left up to packages. |
Also that's a good point, the angle brackets should most definitely not get lowered to multiplication by default, as it would imply some sort of conjugation in the complex case. But yes, it's probably best if it's undefined. |
Should we add julia> ⟨1,-1⟩
-1
julia> ‖1‖*‖⟨1,-1⟩‖
1 |
The lack of nesting is a bit of an issue but perhaps it could be controlled by unbalanced parens, e.g. |
@JeffBezanson I "refactor" it using lowering rule in |
And there is a question. If we do not define julia> vertbracket(x) = abs(x)
vertbracket (generic function with 1 method)
julia> ‖-1‖
ERROR: UndefVarError: vertbracket not defined
Stacktrace:
[1] top-level scope at none:0 |
The ones that are uncontroversial: floor and ceil brackets can just lower to floor and ceil calls. It would be cool if the |
I know that |
I checked the grand table of LaTeX symbols, the total number of brackets is very limited :P |
The total number of syntactic forms should be more limited. It's already probably too big. |
We can change once consensus is reached.
Okay, I will wait for consensus or decision. (but interestingly: julia> x = 1.2
1.2
julia> y = -3.4
-3.4
julia> ‖x + ‖y‖‖
4.6
julia> ‖‖y‖+x‖
ERROR: syntax: extra token "‖" after end of expression ) |
If you want to get any of these changes in, I strongly recommend putting them in separate PRs, since otherwise debate on one part will block all of it. |
Separate them is easy, but how to do it right? i.e., do not give them pre-defined meaning in Base, and without the top-level error? ERROR: UndefVarError: vertbracket not defined
Stacktrace:
[1] top-level scope at none:0 |
Right now you have: (expressions here are not quiet julia functions. they are what you get out of Note that Also I think it is good to support the I want all the bracket types :-) Like making: Beyond the scope of this PR: |
Here is the plan: I will make a separate pr on
The latter four can be added later if we really want them. |
I'm not sure whether we want support broadcast, like |
The expression |
Having the floor and ceiling brackets lower to |
I believe convention is to leave the issue open til the PR is merged. |
I agree, will reopen after beta is out. |
I will pick this up this summer 🕳 |
This is all intriguing, but would need to be done for JuliaSyntax.jl... since flisp is going away. It's likely of no good use to merge (only) for flisp. |
Note: I know nothing about lisp, just start learning it three days ago. This is done by guessing. So feel free to comment or abandon or rewrite.
On this pr: