Iteration protocol: a sentinel value?

Brendan Eich brendan at mozilla.com
Tue May 14 10:28:35 PDT 2013


Please re-read

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

and

http://www.python.org/dev/peps/pep-0380/

/be

Axel Rauschmayer wrote:
> I’m guessing that the semantics are not negotiable, but if they were, 
> I would let an empty `return` terminate the generator, while
>
>     return expr;
>
> would be synonymous to
>
>     yield expr;
>     return;
>
> That would more clearly separate concerns – I’m not too fond of the 
> stopping mechanism (be it {done} or StopIteration) having to play 
> double duty.
>
> On May 14, 2013, at 13:46 , André Bargull <andre.bargull at udo.edu 
> <mailto:andre.bargull at udo.edu>> wrote:
>
>> `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
>
> -- 
> 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>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list