Generator return() and exceptions

Brendan Eich brendan at mozilla.org
Wed Jul 23 12:54:14 PDT 2014


Allen Wirfs-Brock wrote:
> Also, I find some of these questions seem simpler to reason about I think in terms of an iterator with 'next', 'throw' and 'return' methods rather than a generator and its various internal states.

The loop forms are "external iteration" 
(http://esdiscuss.org/topic/generators-vs-foreach) and any throw or 
return within the body should not propagate a useful value to the 
generator implementation of the iterator (if any). The contract is based 
only on .next().

Reifying control effects as exceptions or implicitly invoked methods 
needs a strong rationale. Implicit is worse than explicit. Now is not 
the time to invent without extant use cases.

/be




More information about the es-discuss mailing list