Questions/issues regarding generators

Brendan Eich brendan at
Thu Mar 14 17:13:41 PDT 2013

Andreas Rossberg wrote:
> See my reply to Jason: I think that in most practical cases (in
> particular, all abstractions over iterables), the invocation of the
> iterator method will happen inside an abstraction, and the programmer
> does not have to worry about it.

Talking 1:1 with you after the TC39 meeting, it came out that the ES6 
spec does not say that iterators are iterables whose @iterator does 
"return self". That changes things, but still makes a messier contract 
than you prefer.

The contract you prefer is one where iterables have @iterator and 
calling it gets a (mutable) iterator that is *not* an iterable. It would 
require, as you proposed, making generators return iterables not 
iterators -- an extra allocation.

At the level of contract cleanliness and usability, that may be better 
than the Pythonic convention -- I'm not sure. Cc'ing Jason.

At the level of extra allocations, I still say "boo".


More information about the es-discuss mailing list