Iteration protocol: a sentinel value?

Axel Rauschmayer axel at
Tue May 14 05:51:56 PDT 2013

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;

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> 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]

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list