On Wed, Jul 24, 2013 at 10:59 PM, Jeaye <[email protected]> wrote:
>> 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> { ... }
>
I personally dislike this syntax for iteration, but it would be
consistent with current Rust (just change <name> to <pattern>).
>> - 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.
Do any other languages with similar syntax let you omit the "x in"
part of the "for x in y" when there is no x? Also, of course it's
consistent, it's just a pattern :)
> What would be the trait tied to 'in' that
> allowed any user-created container to be iterated in this manner?
>
`std::iterator::Iterator<T>`. Probably needs to be a lang item with this change.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev