-
-
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
What should we use unprefixed {} brackets for? #10386
Comments
Those are all decent ideas. 1 and 2 seem a bit wasteful; the main reason I like (1) is that curly braces would be very consistently associated with types. (4) is pretty good. In fact this made me notice that there is an erroneous deprecation in place:
As you can see, the suggestion doesn't do the same thing. In our current state there's no easy way to make a 2d array without concatenating, as some have complained about on the lists. Using |
Maybe for (4) we could use |
Another argument for (1) is that tuple types are (currently) covariant. It makes sense that there'd be a special syntax for them — the suggested That said, I could imagine using julia> Tuple{Int, Float64} <: Tuple{Real, Real} # Invariant
false
julia> Tuple{Int, Float64} <: Tuple{{Real, Real}} # Fully covariant
true
julia> Tuple{Int, Float64} <: Tuple{Real, {Real}} # Only covariant in the second arg
false
julia> Tuple{Int, Float64} <: Tuple{Int, {Real}}
true This also seems like an awfully specific use-case, though. |
That undermines the new (soon-to-be) clear separation between array construction and concatenation:
This would put spaces back into the confusing "it depends on how you use them" category. Maybe that's ok. I guess that would mean that you would write these two: [a b c] # construct 1 x 3 matrix with elements a, b, c
[a b c;] # concatenate size(a,1) x (size(a,2)+size(b,2)+size(c,2)) matrix |
Well, it would mean that the |
I would like to refer to #10338 for the concatenation discussion. Even though I don't mind the current decisions, there are also some disadvantages to the rule
But if a new bracket is used for concatenation, I don't think we need to scarify |
I don't see how that can work, since in Typically variance is specified where a type is defined, and not per use. So one can imagine that we've declared I do kind of feel it would be better to distinguish concatenation via brackets, rather than with spaces vs. commas. |
As another point in favor of tuple types, I can imagine using them more in the future, for example for formatted binary I/O:
Something like that requires special syntax inside |
Yikes, I'm not entirely sure I like that. I would also favor writing this as |
Yes |
FWIW, I love the idea of formatted binary I/O. |
Closed by #10380 |
Is it expected behaviour that |
yes, with a deprecation - which isn't working |
Fixed in #10860. I'll merge it once CI greenlights. |
#8578 deprecated the use of
{}
for cell arrays in favor ofAny[]
. That means we will soon have a new set of ascii brackets we can use for a different purpose. This is intended as a Wiki style issue to suggest and discuss different usages, so please help me keep this top post up to date. (I'm pretty sure there is multiple good ideas that I didn't think of now. )Use them for Tuple types. (As suggested in what should we use
{ }
for? #8470 and partially implemented in WIP: redesign of tuples and tuple types #10380)Have them introduce a new block environment, so that they can be used instead of (in addition to) parentheses for grouping expressions.
{(r-a)^2 + (r-b)^2 +(r-c)^2}^(1/2)
Use them to quote expressions, instead of
:()
, which has lots of parsing issues considering how overloaded the:
operator is.Use them to differentiate concatenating, vs. non-concatenating array literals. (Unfortunately this means that you probably want the ability to add a type prefix, which will have a syntax collision with types.)
The text was updated successfully, but these errors were encountered: