Iteration protocol: a sentinel value?

André Bargull andre.bargull at udo.edu
Tue May 14 04:46:55 PDT 2013


`return <expression>` is allowed within a generator [1] and to be able 
to retrieve the <expression>'s value, a (possibly frozen) sentinel value 
doesn't quite work.

A simple example:

function* gen() {
   return 123;
}

var {value, done} = gen().next();
assertEq(done, true);
assertEq(value, 123);


[1] http://wiki.ecmascript.org/doku.php?id=harmony:generators#returning


On 5/14/2013 1:32 PM, Axel Rauschmayer wrote:
> Thanks! Can you elaborate?
>
> On May 14, 2013, at 9:20 , André Bargull <andre.bargull at udo.edu
> <mailto:andre.bargull at udo.edu>> wrote:
>
>> The sentinel cannot carry a return value, from the notes:
>>
>>> DH: Mark's proposal is broken, because it doesn't work with return
>>> values of generators.
>>>
>>> MM: Agreed.
>>>
>>
>>> In the TC39 meeting notes, Mark suggested something similar (but more sophisticated) which was rejected and I am wondering why.
>>>
>>> Herman’s protocol is (roughly):
>>> - Values v: { value: v }
>>> - After last value: { done: true }
>>>
>>> With a sentinel value, this would look like:
>>> - Values v: v
>>> - After last value: SENTINEL_VALUE (defined once, somewhere)
>>>
>>> The latter seems simpler to me – what’s wrong with it?
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de <mailto:axel at rauschma.de>
>
> home: rauschma.de <http://rauschma.de>
> twitter: twitter.com/rauschma <http://twitter.com/rauschma>
> blog: 2ality.com <http://2ality.com>
>


More information about the es-discuss mailing list