-
-
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
Add "Non-Standard Array Literals" by allowing juxtaposition of macro and array #23519
Comments
To me, non standard array liberals would be very useful and this is the shortest path to something reasonable. |
An alternative way of thinking of this is "what else could this syntax possibly mean?" I doubt that expanding a zero-arg macro and using it as the element type would be very useful, and I can't think of any other contenders. |
Yes, @andyferris , a zero-arg macro for element type can still be invoked the same way as it has to be now (as all zero-arg macros): |
For StaticArrays, there might be an alternative approach: Overloading SArray[1 2; 3 4; 5, 6] would need to be lowered to typed_hvcat(SArray, Tuple{2, 2, 2}, 1, 2, 3, 4, 5, 6) instead of the current typed_hvcat(SArray, (2, 2, 2), 1, 2, 3, 4, 5, 6) Not sure it's worth the effort of doing it (and the macro approach described here might still be wanted in addition), but I'd say it's worth thinking about. EDIT: Ref. #16740 (comment) |
Yes we've discussed this before. We had concerns about extending what is already a pun on getindex even further, however it is still a viable option. I definitely don't think This is possible with a placeholder e.g. |
I'm not 100% sure I understand your concern. Is it because you would like to create an |
That's right. For instance I already use I think some general cleanups as in #16740 would be wonderful, and I really like the |
TLDR: Please, allow parsing
@foo[1, 2, 3]
as a shortcut for@foo([1, 2, 3])
.Too many times, when using StaticArrays, I write stuff like
which fails with
ERROR: syntax: invalid macro use "@((typed_vcat SArray (row 1 2) (row 3 4)))"
I then add a space between
@SArray
and[1 2; 3 4]
which also fails since the macro tries to consume the whole[1 2; 3 4] * v
expression.The right way to do it
It would be nice to be able to this without the parentheses...
Yes, I know, it's not that cumbersome to type two extra characters... but on the other hand, this syntax is available and making it work will hopefully not introduce many accidental bugs.
This could be seen as a kind of "Non-Standard Array Literals".
(related: #8934, #7128, #6960, #8892, #7128)
(Had I the knowledge of Julia parser I would open a PR instead of an issue, but I'm a null at scheme.)
The text was updated successfully, but these errors were encountered: