2 ms·
I've tried to find any meaningful example of "why not." Is "let" supposed to be needed because of something like this? let (a, b) = get_tuple_of_two_ints();
by acqq 13y ago
I've tried to find any meaningful example of "why not." Is "let" supposed to be needed because of something like this?
let (a, b) = get_tuple_of_two_ints();
I don't see that it's fundamentally different to parse if it would be written like this:
(a, b) := get_tuple_of_two_ints();
It's true that the parser has to wait for := to do know the semantics of the expression on the left side of it, but it can definitely be done.
- bjz_ 13y agoRust can pattern match on structs, fixed length vectors, references, and it has keywords to bind them as mutable and/or by-ref. Doing all that without a `let` would extremely challenging.
- pcwalton 13y agoIt would require making "expression" and "pattern" into the same nonterminal in the grammar, and then deciding afterwards whether something that was parsed was an expression or a pattern. This is sometimes called a "cover grammar" because it "covers" two distinct nonterminals. It is possible--ECMAScript 6 does it--but it's definitely a complex way to parse. It doesn't seem compatible with Rust's design goal of being easy to parse and regular, e.g. for tooling.