Uh oh!
There was an error while loading. Please reload this page.
Change array syntax to prevent ambiguity introduced by RFC 439 - #520
Conversation
mahkoh
commented
Dec 14, 2014
This is better than the .. syntax even if there were no ambiguity. |
quantheory
commented
Dec 14, 2014
There was a problem hiding this comment.
This sentence is kinda awkward.
There was a problem hiding this comment.
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.
mdinger
commented
Dec 14, 2014
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]; |
petrochenkov
commented
Dec 14, 2014
FWIW, |
nrc
commented
Dec 14, 2014
I much prefer |
glaebhoerl
commented
Dec 14, 2014
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? |
nrc
commented
Dec 14, 2014
@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 |
Kimundi
commented
Dec 14, 2014
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 |
mdinger
commented
Dec 14, 2014
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 |
quantheory
commented
Dec 15, 2014
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: |
sinistersnare
commented
Dec 15, 2014
+1 for |
nikomatsakis
commented
Dec 15, 2014
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 ( |
quantheory
commented
Dec 15, 2014
Can you elaborate? Specifically:
I ask because I want to know if this could be addressed by changing the proposal to either |
nikomatsakis
commented
Dec 16, 2014
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, |
quantheory
commented
Dec 16, 2014
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 |
nikomatsakis
commented
Dec 16, 2014
I agree that |
nrc
commented
Dec 16, 2014
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 |
alexcrichton
commented
Dec 16, 2014
Sprinkling some more sigils (perhaps other options): Purely just food for thought! |
sfackler
commented
Dec 16, 2014
I'm not a huge fan of |
ben0x539
commented
Dec 16, 2014
|
sfackler
commented
Dec 16, 2014
The |
tikue
commented
Dec 18, 2014
I find |
mcpherrinm
commented
Dec 18, 2014
I am strongly opposed to |
quantheory
commented
Dec 18, 2014
@nick29581: True. It seems that |
xgalaxy
commented
Dec 18, 2014
I prefer the |
engstad
commented
Dec 18, 2014
Please note that in OCaml, you write lists like this: For me, and anyone else used to OCaml, this would be a huge surprise. |
rkjnsn
commented
Dec 18, 2014
I like |
glaebhoerl
commented
Dec 18, 2014
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. |
sinistersnare
commented
Dec 18, 2014
@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] |
engstad
commented
Dec 18, 2014
@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 |
pnkfelix
commented
Dec 18, 2014
@engstad If by (You may instead mean that |
quantheory
commented
Dec 18, 2014
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. |
netvl
commented
Dec 18, 2014
I really do like |
eddyb
commented
Dec 18, 2014
@netvl I've always found LLVM's |
dlesco
commented
Dec 18, 2014
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. |
nrc
commented
Dec 19, 2014
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 |
tikue
commented
Dec 19, 2014
\o/ |
dobkeratops
commented
Dec 26, 2014
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. |
tikue
commented
Dec 26, 2014
I seriously doubt |
dobkeratops
commented
Dec 26, 2014
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. |
eddyb
commented
Dec 26, 2014
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