On 10-09-23 04:55 AM, Peter Hull wrote:
The syntax of alt ... case changed recently to drop the '()' and add
in a '?'. Just as a matter of interest, why was this? Particularly the
'?'.
The change accompanied the shift from function-like to constant-like
0-ary tag constructors. Now a 0-ary tag constructor is denoted merely by
its name; as a consequence the pattern syntax had to change to
disambiguate 0-ary tag constructors from fresh slot bindings. For example:
tag colour {
red; green; blue;
}
fn main() {
auto x = red;
alt (x) {
case (red) {
// Should this bind a new variable 'red'?
// or should it match tag colour, constructor 'red'?
}
}
}
With the current rule, '?red' binds a new slot whereas 'red' matches the
constant tag constructor. I'm happy to reconsider syntax here; it was a
change made in order to facilitate disambiguation, not because I am
particularly wedded to the ?foo syntax.
The default case is still (_) - could this be changed to (?) to make
it more consistent?
Possible, sure. Though the wildcard symbol is not only applicable to
top-level, and "foo(?,?,?)" reads a fair bit worse than "foo(_,_,_)" to
my eyes. I'd be happy to pursue any sort of alternative, more appealing
pattern syntax you can think up, so long as it's unambiguous, familiar
looking, and easy to parse. I don't like sigils any more than the next
non-perl-programmer :)
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev