Le 12 juin 2013 à 18:14, Andreas Rossberg <[email protected]> a écrit :

> On 12 June 2013 14:12, Claude Pache <[email protected]> wrote:
>> 
>> <snip>
>> 
>> On the other hand, I see a small advantage of the "weird" requirement for 
>> iterators to be iterables themselves: It allows to discriminate between true 
>> iterators and merely  "nextable" objects.
> 
> And in the spirit of "duck typing", why would you want to do that?

Just so that an error is surely thrown in case I feed a for/of loop with a 
non-iter{ator|able}. In the spirit of duck-typing, I consider that "having an 
`@@iterator` method" is a more robust check than "having an `@@iterator` or a 
`next` method". Not a big deal, however.

> And
> how do you want to treat an iterable with a 'next' method, but whose
> @@iterator method does not return 'this'? Is that a "true" iterator?
> (The fact that such a beast can even exist shows how fuzzy those
> notions are.)

You're right, but I don't expect to encounter such a beast often. Concretely, 
they are buggy objects that would not receive any special treatment (they are 
iterable whenever an `@@iterator` method is expected, and they are iterated 
whenever a `next` method is required).

–Claude

> 
> /Andreas
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to