On 05/06/2013 9:15 PM, Patrick Walton wrote:
On 6/5/13 9:09 PM, Daniel Micay wrote:
I think extending the built-in `for` loop to work with external iterators
should be considered, because right now the verbosity discourages
using them
and makes borrow checking more painful than it has to be.

It could treat functions as internal iterators, and look for an
`Iterator`
implementation (using a `lang` item) for external ones.

Python's `for` loop starts by looking for an iterator (a `__next__`
method) and
falls back to an iterable (an `__iter__` method) so behaviour like
this isn't
an alien concept.

This is a very well-thought out post, and I find it persuasive. The
mutability issue is one I hadn't considered, and seems to make a good
argument for including both in the language.

Yeah. I think it's clear enough that both have their (strong) advantages; we have hashmaps and treemaps too, and both vectors and lists :)

The main thing I'm concerned with is making the interfaces to user code smooth enough that neither feels markedly second-class or unusable. Extending 'for' as you suggest sounds like a good step.

It might also be good to add a tutorial chapter on the matter, introducing these terms and relating them together, so users can see the relative use cases.

Thanks for the ongoing work in this area!

-Graydon

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to