We had some discussion recently about reforming the for-loop syntax since we'll be switching it to external iterators and it's a bit deceptive to the user to be writing a lambda-pattern there.
Have we yet considered C++11's approach to this?

    for <name> : <expr> { ... }

This seems pretty consistent to me at first glance, considering how we use a similar syntax to declare and initialize fields. Consider <name> being initialized by <expr> for each value in <expr>.

  - No-pattern form now requires a dummy pattern. That is, we can't do:

      for 10.times { ... }

    anymore, rather we have to write:

for _ in 10.times() { ... }
If we do go this route, I think this new idiom is actually a good thing. `for 10.times { }` seems a bit too clever, whereas the latter is entirely predictable, albeit slightly more verbose.; it's also entirely consistent with our usage of _ elsewhere. What would be the trait tied to 'in' that allowed any user-created container to be iterated in this manner?

I found it more interesting to note that, should we take 'in' as a new keyword, it's a perfectly reasonable keyword to reuse for the putative "allocation expressions" we've been talking about needing for supporting C++-like placement-new.
That's a really good idea and seems entirely logical, coming from C++.


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

Reply via email to