How would shallow generators compose with lambda?

Igor Bukanov igor at
Thu May 14 16:36:26 PDT 2009

2009/5/14 Brendan Eich <brendan at>:
> function gen(arg) {
>    foo((lambda (x) yield x), arg);
> }
> function foo(callback, arg) {
>    try {
>        callback(arg);
>    } finally {
>        alert("I'm ok!");
>    }
> }
> g = gen(42);
> print(; // tell the user the meaning of life, etc.
> g = null;
> gc();
> I think finally is the only issue, since how else can you tell that foo
> didn't see a return or exception from the callback?
> It's true that this finally-may-not-run wrinkle is confined to generator
> functions in JS1.7, i.e., without lambda.

lambda can be combined with the generators if the yield semantic would
be altered to execute any finally block it resides in in the same way
the return does. Then in the above example the alert would be executed
when the lambda does yield.

This is how continuations in Rhino works with any continuation long
jump respecting lexical finally blocks.


More information about the es-discuss mailing list