Questions/issues regarding generators

Kevin Reid kpreid at google.com
Thu Mar 7 08:50:04 PST 2013


On Thu, Mar 7, 2013 at 8:39 AM, Andreas Rossberg <rossberg at google.com>wrote:

> On 7 March 2013 16:37, Andreas Rossberg <rossberg at google.com> wrote:
> > But, in order to (hopefully) let Brandon calm down a bit, I am NOT making
> > yet another proposal for a two-method protocol. Instead I propose
> > simply _delivering_ a sentinel object as end-of-iteration marker
> > instead of _throwing_ one.
>
> Forgot to mention one detail: under this approach, it should of course
> be a runtime error if yield is applied to a value that is a
> StopIteration object.


Use of a singleton (or not marked for the specific generator) sentinel
object has a hazard: the sentinel is then a magic value which cannot be
safely processed by library code written to operate on arbitrary values,
which happens to use generators in its implementation.

(ECMAScript already has moderately hazardous values, namely objects-as-maps
which do not implement the 'standard protocol' of Object.prototype methods,
but these are more hazardous than that in that they are not even safe  to
pass around without operating on them.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130307/434cc3e9/attachment.html>


More information about the es-discuss mailing list