On Tue, May 17, 2011 at 10:08 PM, Marijn Haverbeke <[email protected]> wrote:
>> Why the need for two keywords? Couldn't the inferred version simply
>> omit the type?
>
> It could, but that'd require backtracking in the parser, and we'd like
> to keep Rust easy to parse (for speed, for our own convenience, and
> for the convenience of external tools).

Depends on the exact syntax you want, I suppose, but this could be
done with at most single token lookahead right? Simplest option (no
lookahead needed):

let x : int = 5;
let y = x;
let z : int;


Here the second token is always the identifier, and then there's two
optional bits that can be uniquely identified by the first token (the
next token must either be ":" or "=").

Even this option is easy:

let int x = 5;
let y = x;
let int z;


You only need to look one token ahead to know what the second token
was (if the third is not "" or "=", then the second token must've been
the type).

-- 
Sebastian Sylvan
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to