On Thu, Jan 1, 2015 at 2:49 AM, Pim Schellart <[email protected]> wrote:
> why can’t one simply write:
>
> let a = [1i, 2i, 3i];
>
> for e in a {
> println!("{}", e);
> }
>
> and have the compiler figure out that ‘a’ has ‘.iter()’ and use it? The form
> without .iter() just feels more natural to me in this case.
> Please feel free to tell me to RTFM or ask this question elsewhere.
That's what Python does. But then, in order to be able to iterate over
iterators, iterators must also have iter() methods, which presumably
return self, which is an additional source of implementation errors
and isn't really reasonable because it would have to consume the
original reference, invalidating it, which is super annoying. (You
couldn't do "for x in a {...} a.foobar()"
FWIW there are side benefits to not doing this automatically -- in
Python, the difference between an iterable and an iterator is subtle,
and the selection of "default" iterators for many types is also
confusing. e.g. for dictionaries/mappings, one might reasonably
iterate over keys, values, or key-value pairs, which is the default?
-- Devin
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev