-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
slightly different array literal syntax to distinguish from slices #1797
Comments
Or we could use a builtin:
|
A few ideas: var hi = "hi"; |
I'll admit this has bitten me a lot. Love the underscore idea; when I see the Edit: @raulgrell the |
@hryx Yeah, that's one of it's greatest weaknesses but also its greatest strength: When slicing, IT occurs on the right of a name, it takes an index and it and refers to a value It's similar to the symmetry with declaring a pointer type with a prefix |
Related: #568 |
Ah, I was looking for that, thanks @Hejsil. Looks like @thejoshwolfe made an identical proposal to this one in a comment on that issue. |
I need this for #2602 so I'm going to do this in master branch right now. |
Guess what
@typeOf(mystery)
is:It's
[1][]u8
. It looks like a double slice, but it's actually an array literal with an inferred number of items. It is equivalent to:This is important because arrays usually can not be used where slices are expected, and it starts to get confusing with
const
, especially when you consider that there is a missing compile error for this:The
const
on the array literal is nonsense and should be a compile error.It's nice to infer the number of array items, but it shouldn't look like a slice. How about this syntax instead?
The text was updated successfully, but these errors were encountered: