11-05-17 I posted a note here mentioning some syntax churn going on.
Some of that has happened in the past month, some required further
discussion. We had an all-day intense session in Toronto a couple weeks
ago and hashed out a few fine details, which we took notes of but forgot
to post publicly. This is the result of that discussion:
- Type foo<T> in declarations, with foo::<T> only in expression
position to disambiguate against binary <. Since it's usually
inferred, few programs wind up seeing foo::<T> in practice.
- tag T = <type>; declares a general nominal type, which can be
a record, object, whatever. Reads like "type T = ..." but is
constructed by juxtaposing the name T with the constructed
value on the RHS.
- Paren-free change to if, alt, while, for. Braces required for
bodies.
- alt also loses the 'case' word. Full form is:
alt <val> { <pat> { <block> } <pat> { <block> } ... }
- rec constructor changes to {label:<expr>, ...}
- rec type changes to {label:<type>, ...}
- let changes to let <pat> = <expr> for irrefutable pats.
- Numerous pattern extensions:
- <pat> | <pat> for alternatives
- <pat> ... <pat> for *scalar* ranges
- {label: <pat>, ...} to match rec constructor and type
- ident=<pat> is a value-capture
- &ident=<pat> is an alias-capture
- ident sugar for ident=_, a capture, no question mark;
ambiguity with nullary tags is resolved by requiring
a :: somewhere in nullary-tag name. Prefix :: is permitted.
- {x, y} sugar for {x: x, y: y} (thus {x:x=_, y:y=_})
- {&x, &y} sugar for {x: &x, y: &y}
- "..." is permitted in rec patterns, as is matching fields
out of order; patterns are typechecked top-down anyways.
- <pat>:<ty> to ascribe a type
(let x:int is simply a special case of this)
- tuple to go; use structural records and give fields a name,
tags apply to anything so tag-arms are not implicit tuples
either.
- function-calls do not support keywords. yet. but the feature
seems like it may drift into focus since some symmetry is
present.
Phew. Sorry if any sacred cows died here. Very constrained space, not a
lot of wiggle room.
Note that I will be performing these changes en-masse using the pretty
printer when I can get it stable enough to lean on permanently this way.
I'll announce such flag days a couple days in advance, so people have
time to get their WIP patches in.
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev