-
Notifications
You must be signed in to change notification settings - Fork 1.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
Change array syntax to prevent ambiguity introduced by RFC 439 #520
Conversation
This is better than the .. syntax even if there were no ambiguity. |
arguments (or for slice patterns under the `advanced_slice_patterns` feature | ||
gate). This RFC does not change that. In a match pattern, `..` will always be | ||
interpreted as a wildcard, and never as sugar for a range constructor. This | ||
restriction may be lifted backwards-compatibly in the future, if it becomes |
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.
This sentence is kinda awkward.
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'm not sure what I was trying to say, and any change to match patterns is supposed to be "unresolved" anyway, so I just took this sentence out.
One nice thing is it isn't larger; it is exactly the same length as before. It does read nicely: let a: [uint, ..2] = [0u, ..2];
let a: [2 of uint] = [2 of 0u]; |
FWIW, |
I much prefer |
But it doesn't make any literal sense. "An array containing five of this thing" is a meaningful expression. "An array containing this thing for five" isn't. Am I missing something? |
@glaebhoerl I don't think you're missing anything. It's just that PL syntax is usually not read so literally. However, now that I think about types a bit more, we use |
You can just spin it as "repeated for 5 times". One thing I didn't see mentioned here explicitly is how it interacts pedagogically with unsized array coercions. Right now, a |
Technically you're somewhat limited by English here I supposed. I buy 3 apples or 7 peaches but never apples 3 or peaches 7. Even so, we're trying to write it You can read Why avoid a new keyword? Aren't words like |
As you might guess from the RFC, I think that avoiding too much semantic overloading on
Hmm, I guess that wasn't my mental metaphor at all. I think of the That said, I still don't have a strong opinion on I don't think that swapping the order is that much harder to script. I'm probably mixing up regex dialects here (the escapes for brackets are ugly), but something similar to Edit: Actually, this is a smarter perl-ish regex, but you'd have to run it multiple times for files with nested arrays: |
+1 for |
One big problem with this suggestion is that, in the type position, we don't know whether we are parsing a type or an expression ( |
Can you elaborate? Specifically:
I ask because I want to know if this could be addressed by changing the proposal to either |
On Mon, Dec 15, 2014 at 02:52:32PM -0800, Sean Patrick Santos wrote:
Yes, and specifically in the type position (not expression). The
No, because
Those options would address the concern I raised, yes. That said, I am not particularly keen on any of those choices, though, |
Well, I think it's just genuinely hard to come up with something better. Other words that come to mind are "number", "times", "across", "repeat", "duplicate", "multiply", "extend", "expand", "over", "at", "size", "length", "dimension" and "on". Not all of these are clearly better, most are too long unless abbreviated, and most seem more likely to be troublesome as reserved keywords. (Actually, for some reason I do like
I think that would be a bit weird. If it was contextual rather than reserved, that allows funny expressions like My inclination is to replace this proposal with one for |
I agree that |
We had a bit of a discussion about this at the weekly meeting this week. The room was broadly in favour of some change and we agree there is some urgency in making this decision. No one was super keen on any particular proposal though. We did decide context-sensitive Therefore I would like to propose |
Sprinkling some more sigils (perhaps other options):
Purely just food for thought! |
I'm not a huge fan of |
|
The |
I find |
I am strongly opposed to |
@nick29581: True. It seems that |
I prefer the |
Please note that in OCaml, you write lists like this:
For me, and anyone else used to OCaml, this would be a huge surprise. |
I like |
I don't think trying to "count votes" based on this discussion thread makes very much sense, because many of the options were introduced midway through, and it also wasn't advertised as being a vote. If ever there was an occasion for the core team to hold a meeting and make an arbitrary decision, this seems to be it. |
@engstad note that this is type and repetition syntax. The syntax you mention (when translated to rust) is still valid. let xs: [u8, ..3] = [1, 2, 3]; // fixed sized array containing [1, 2, 3]
let ys: [u8, ..3] = [1, ..3]; // fixed sized array containing [1, 1, 1] |
@sinistersnare I was arguing against the I think the main cause of debate here is the repetition syntax, not the type syntax. Why do we even have repetition syntax? Can't we use macros for it? As far as type syntax goes, I also feel that we should just get rid of it. Let's just use |
@engstad If by (You may instead mean that |
This was discussed in the other proposal, and it turns out that the macro system can't replace the repeat syntax in constant expressions, which is a very common use case. |
I really do like |
@netvl I've always found LLVM's |
It's too bad @ may be confused with match pattern binding. A current meaning of the @ symbol is the French word 'à' (or Italian/Spanish/etc word 'a'), and that word's meaning includes 'to' or 'by'. They are descended from the Latin word 'ad', as in 'ad infinitum.' So
That sounds like a vector to me. |
This RFC has been accepted, r=nikomatsakis. I'm meant to write a bit more about the discussion that led to acceptance here, but I believe that has mostly been played out in the comments. This is really a case of making a call and picking the least bad syntax, so there is no super strong argument against the other suggestions, just that |
\o/ |
I see this has been accepted. I was going to mention, the absence of ';' in types makes simplified parsing (e.g. in syntax highlighters? )easier. I think its' possible to simply/cheaply disambiguate < .. > for typeparams by scanning between a '<' and if you don't find various characters ({ } ;) its a good assumption its' a type-param. [T x N] looked like the best proposal to me above, similar to LLVM syntax.its 'longer' but the space is easy to type. I think the [ ] with ";"'s inside has other interesting potential uses better than an array type. |
I seriously doubt |
its not impossible but it closes other uses of the ';' character. Currently the absence of semicolons in types is nice, IMO. designing my own language syntax(layered on Rust), it seems really helpful to use the combinations of {} () [] and internal delimiters , ; for 'other things'.(map literals? list comp ? whatever ..). I think the syntax has better uses than this and it closes future doors. and generally since experimenting I seem to have learned semicolons help disambiguating type-params.(as in, separating types from statements)... I think this is a 'happy accident' that kept When you know types dont include ';' I think its's possible to make a simplified lookahead without needing a whole GLR parser. ';' says statements, or data separator. |
You don't need to disambiguate type params with a hack, but I guess the lack of an official grammar doesn't help with writing proper syntax highlighters. Using |
Change all instances of the [_, ..n] array syntax to the new [_; n] syntax. See rust-lang/rfcs#520 and rust-lang/rust#19999
Update: This request is now about syntax resembling
[x; N]
rather than[N of x]
. I am still open to changing this if needed, but we need a decision very soon. The other leading candidate is[x for N]
.This is an alternative to #498.
The change is not complex; most of the length of the RFC is due to my getting carried away when listing alternatives. I'm still open to changing details (e.g.
[x by N]
or[x for N]
instead of[N of x]
), but this is my current preference, and I feel that something along these lines is preferable to fixing this via a change to the RFC 439 range syntax.Rendered View