-
-
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
Adding new brackets to Julia - ideas wanted #8934
Comments
I'd prefer to leave them free for packages to use. |
Letting packages define a meaning for them might also be confusing, in particular if they differ much. I remember being very confused by a python package using Maybe |
This issue here is that funny-shaped brackets don't really have a canonical meaning either in mathematics or in programming languages, so it doesn't really make sense to me to "bless" a meaning in The fact that |
Decisions made in parsing strategies tend to favor particular usages. For example, if the parser only recognizes commas to separate exprs' inside, it tends to favor a collection/ indexing type of usage. If the parser allow two kinds of separators (says, commas and semi-colons), it enables matrix usage. Maybe we want more kinds of separators. Maybe certain reserved words inside will change its meaning, like Another note on multiple dispatch, since the brackets would be mapped to standard calls, e.g. I think a common usage would look like this (updated):
where Or, we would just use it in macros. The brackets parse, and the package can use them. I could see it having some potential use in DataFramesMeta.jl, but I'm completely shooting from the hip here. |
You'd almost definitely want the brackets to parse to a macro call, since that gives the implementor the most flexibility (similar to You make a good point about the intended use affecting the parsing, though. I can definitely see it being useful to parse |
@one-more-minute , yes they all parse into macros first in the WIP PR. And you have a good point about passing the symbol, especially for a ref-like And to your point I would like to reserve Brace |
Sounds good. You may be aware of this but just in case, I'll mention that you don't need macro struckcurlycall(f, args...)
Brack_call($(Expr(:quote, f)), $(args...))
end Then (Apologies if I just misunderstood what you meant by "reserved", though) |
@one-more-minute your suggestions have been incorporated into the PR. |
+1 to @one-more-minute 's comments. |
Thanks for the input. To summarize, I now have square bracket do this macro call_Brack( args... )
esc( Expr( :call, :call_Brack, args... ) )
end And, Brace bracket does this: macro call_Brace( sym, args... )
esc( Expr( :call, :call_Brace, Expr(:quote, sym), args... ) )
end So we cater to two types of usage
The lowering of the enclosing form (without prefix) is the same for all brackets. For example: macro enclose_Brack( args... )
esc( Expr( :call, :enclose_Brack, args... ) )
end |
Reaction is too mixed. I'm closing it. |
Related issue: #7128
A proof-of-concept PR: #8892 (more technical discussions inside)
Currently, we have
(), [], {}
. We could introduce more bracket types to Julia so oft-used functionalities are more convenient to use, such as non-concatenating array/matrix construction, perhaps even with some "leftovers" that modules can use to enable terser and more readable code (the latter is much motivated by my selfish reasons).The PR proposes three new bracket types:
⟨⟩,⟦⟧,⦃⦄
(which can be entered by latex symbols \langle,\rangle, \lBrack, \rBrack, \lBrace, \rBrace).⟦⟧
and⦃⦄
also have ASCII equivalents[| |]
and{| |}
, respectively.They are mapped according to whether there's something in front of the brackets. For example,
(some_expression)⟦args...⟧
is mapped to@Brack_call( (some_expression), args... )
, and⟦args...⟧
is mapped to@Brack_enclose( args... )
. The macro definition is in base and is currently defaulted toBrack_call
andBrack_enclose
generic functions in these examples. These can be stagedfunction, obviously, and it is part of the discussion below. Type signatures would provide the customization on actual behavior.The key question is what kinds of functionalities should these new brackets be used for? Note that:
⟦⟧
for matrix construction, there are decisions on treatment on space, commas, semicolons, or perhaps even newlines, and how to make higher dimensional construction "easier", etc.g{| a, b, c |}
to mean some kind of "lifted" function call, we may want to parse the list as argument list.With respect to the PR, let's use this issue to keep track of design/usage ideas (my lisp code ugliness 😄, unicode issues etc. can be done in the PR ).
The text was updated successfully, but these errors were encountered: