One more thing worth pointing out is that a singleton does not work due to "return e" in generators needs to signal an end to iteration with a value. The wiki does this be creating a new object with a "value" property and [[Class]] set to "StopIteration"
Instead of returning a singleton we can return an object with two fields, {value: v, done: b} and when we see a "return e" in a generator this becomes {value: e, done: true}. https://gist.github.com/anonymous/5108939 On Thu, Mar 7, 2013 at 11:50 AM, Kevin Reid <kpr...@google.com> wrote: > On Thu, Mar 7, 2013 at 8:39 AM, Andreas Rossberg <rossb...@google.com> > wrote: >> >> On 7 March 2013 16:37, Andreas Rossberg <rossb...@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.) > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -- erik _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss