-
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
Amendment to RFC 439 for grammar ambiguity #498
Conversation
+1 |
Should we yank |
I agree that it's a bit asymmetric, but I believe it would be backwards-compatible to add |
While I agree that |
@tikue The short answer is: the existing syntax emerged only after a very long bikeshed, and time until 1.0 is very short. |
The bikeshed wasn't aware of the conflict with the |
I’m not 100% sure that I like this way of resolving the ambiguity. It just makes the syntax inconsistent: people expect to be able to write |
If the It would make range literals weird though. |
@P1start that completely defeats the purpose of this particular RFC: that a..b is sugar for a |
@sinistersnare |
Ah yes I forgot about that. Damn. @tikue No it does not, this PR is to remove syntax due to ambiguity, and I was trying to resolve it |
@sinistersnare my comment was directed at @P1start |
Ah ok :) |
@tikue I wouldn’t say that the entire point of that part of the RFC was to make |
Ok, from that perspective it makes more sense. Still, going from the inconsistency of allowing |
The array syntax was always terrible, I don't see what 1.0 being close has to do with resigning to supporting it forever. Changing it a mere syntactic change unlike dozens of other features that are changed/introduced now which have semantic components. |
Agreed. The cons of changing array literal syntax now are:
The pros are:
The benefits of the pros will outlive the short term pain of the cons. |
I personally think the array syntax is nice enough, and I'd have a hard time coming up with a better one. I assume the people saying we should change it do have a particular syntax in mind? But debating it here would unduly derail this thread, so the best way forward would probably be to start a bikeshedding thread on discourse, and then come back with it here if there's consensus around some better option. |
This may be true in the standard library, but it is not obviously true in general. In the original RFC 439, the different
Removing
(Note also that if such applications of slicing syntax are allowed, the |
@quantheory Those are some excellent points. FWIW, if some clever person wants to devise a better solution that retains fulls symmetry and removes the ambiguity, I'd be all ears! I tried to stay away from revising the fixed array syntax, since that was apparently the result of a massive bikeshedding effort, but perhaps things have changed since then. Given that this PR is entirely about a syntactic change, I don't personally have a problem with such discussion happening right here. |
If you mean rust-lang/rust#9879, the reason they were reevaluating the array syntax (as the bug notes) is because it's ugly. Not because it's conflicting. They also didn't find anything much better or have a dire need. |
I am in favor of anything that can resolve the ambiguity and is not obviously worse than the current fixed-array syntax . I prefer reusing symbols if possible. It'd be nice if something could be chosen that would look equally nice for the type syntax.
I haven't thought hard about these; some probably have obvious issues. |
No, I was referring to a long mailing list thread that @nikomatsakis showed me, which I think predated this issue. |
Perhaps we could just do away with the array repeat syntax altogether. It can’t be used for much other than arrays of scalars (due to how it only works for macro_rules! repeat {
($e: expr, $n: expr) => {{
let r: [_, ..$n] = ::std::mem::uninitialised();
let e = $e;
// Do some unsafe magicks here, copying e (perhaps with .clone())
r
}}
} Unfortunately, that wouldn’t work in constant expressions unless we got CTFE. And constant expressions are a pretty common use case for the array repeat syntax. |
@tikue I could live with several of those, personally. :-) |
-1. I don't like the asymmetry; it would be very surprising that |
Hm, thinking a bit more about @tikue 's proposals: struct T;
const N: uint = 5;
let a: [T]{N} = [T]{N}; // Seems verbose, might be ambiguous with one-element array expressions?
let a: [T #N] = [T #N]; // This seems like a decent option
let a: [T, #N] = [T, #N]; // Might be ambiguous with attributes-on-expressions
let a: [T, ||N||] = [T, ||N||]; // I think this one is too verbose :P
let a: [T in N] = [T in N]; // Might be ambiguous with the new placement expression proposal
let a: [T @ N] = [T @ N]; // Might be a problem if we ever want to make @ a prefix operator again
let a: [T, for N] = [T, for N]; // I like his one, but it might be a parsing ambiguity with for-loop expressions.
let a: [T for N] = [T for N]; // This one (without comma), I think, does not have a parsing ambiguity
let a: [T => N] = [T => N]; // Feels a bit verbose, and looks like matching or mapping. I think of these, the |
Also: let a: [T by N] = [T by N]; // Probably closes to nice `[T * N]` which @bjz noted
let a: [T, by N] = [T, by N];
let a: [T at N] = [T at N];
let a: [T, at N] = [T, at N];
let a: [T dup N] = [T dup N]; // duplicate
let a: [T, dup N] = [T, dup N];
let a: [T times N] = [T times N];
let a: [T, times N] = [T, times N];
let a: [T rep N] = [T rep N]; // repeat
let a: [T, rep N] = [T, rep N]; |
@mdinger, I think the idea was not to introduce new keywords. Anyway, shouldn't this be discussed in a separate RFC? |
I was not aware of that. |
There's also no reason why the |
Heh, another idea (It won't parse because of the Or operator however):
|
These could extend to multiple dimensions if that was ever an explicit goal: // Using `for`
let a: [T for N by M by W] // If this made sense:
// These 3 are equivalent:
let a: [T for N by 1]
let a: [T for 1 by N]
let a: [T for N]// same as suggested by @kimundi
// Flipped and using `of`
let a: [N by M by W of T]// If this worked
// These 3 are equivalent
let a: [N by 1 of T]
let a: [1 by N of T]
let a: [N of T] |
In terms of more radical changes:
, which is extensible to
|
I would personally prefer range literals to only be allowed in If we're up for bikeshedding a change to the array syntax, why not axe the |
@sfackler Expanding |
My preference would be, in this order:
I thought that the two uses of At the same time, the only reason for keeping the current array repeat syntax seems to be that we already have something implemented, and there are so many acceptable alternatives that we won't be able to choose an alternative. (That's what bike-shedding means, after all!) It would be a shame if the intuitiveness (and to some extent functionality) of slicing syntax was sacrificed in order to preserve an array repeat syntax that is not bad, but still basically arbitrary and not set in stone pre-1.0. |
FWIW, I think @mdinger's idea |
Of the fixed length array syntaxes, I prefer Given the time frame, I think we need to move quickly on any syntax change. There seems to be broad agreement here at least that changing the syntax of repeating arrays is better than losing symmetry in ranges. Could somebody write up a short, strawman RFC for such a change (plus changes) so we can see if there is resistance to the general idea and/or if a wider audience has opinions/ideas on the exact syntax. I can implement whichever change we choose (I am currently working on the range/slicing changes), but we need to reach a decision very quickly if the implementation work is going to be done by Jan 9th. |
I like the version using "of" and am writing up an RFC for it. I have changed actually changed my mind a bit about using "for" even though it avoids a new keyword; I'll explain that in the RFC. |
I'm going to close this RFC in favor of changing the fixed-size array syntax. Thanks for the feedback! |
This amends the
cmp
/ops
reform RFC to deal with the grammar ambiguity around..j
notation.