> for <pattern> in <expr> { ... }
I really like this notation. And there's actually a better reason for
switching to a new syntax other than "it's a bit deceptive to the user to
be writing a lambda-pattern there". Namely, given strcat's plan to allow
iteration automatically on anything that implements Iterator or Iterable,
the following is actually ambiguous:
for foo.bar |i| { ... }
In our current `for` notation, we allow one to omit parentheses for empty
argument lists. Thus, in the above loop, we have no idea if `bar` is a
member of `foo` that implements Iterable or if `bar` is a method that
evaluates to an Iterable! To disambiguate we would have to require
parentheses, and this would create an inconsistency with `do` notation.
> it's a perfectly reasonable keyword to reuse for the putative "allocation
expressions"
I'm all for reusing `in` in other contexts. Placement new is one that I
hadn't thought of. I was actually thinking of something along the lines of
overriding shadowing in match statements:
let x = 2;
let y = match (4, 3) {
(x, 3) => x,
_ = 0
};
The above code will assign 4 to y, because the pattern `(x, 3)` shadows the
outer declaration of `x`. Now imagine we had something like the following:
let x = 2;
let y = match x in (4, 3) {
(x, 3) => x,
_ = 0
};
Rather than shadowing `x`, the above could allow us to use the existing
definition in the pattern.I don't know if anyone else thinks this would be
useful, I'm just pointing out possibilities.
> It's not entirely clear to me that this pattern alone warrants keeping
'do'.
As a professional Javascripter, I implore you keep `do` as it is. It really
and truly is a world of difference between:
do foo {
...
}
and:
foo(|| {
...
});
It's one of my favorite features of Rust, and it makes higher-order
functions feel like first-class citizens.
> for _ in 10.times() { ... }
As the original creator of `10.times`, I was under the impression that we'd
be moving from `for` to `do` once this change is complete. As in:
do 10.times { ... }
I'm baffled as to why people think something so simple and intuitive is
"clever". :P
> for <name> : <expr> { ... }
-1. The `:` symbol is already hugely overloaded, and it's less readable to
boot.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev