How would shallow generators compose with lambda?

Mark S. Miller erights at google.com
Thu May 14 14:10:19 PDT 2009


On Thu, May 14, 2009 at 1:22 PM, Brendan Eich <brendan at mozilla.com> wrote:
> On May 14, 2009, at 12:24 PM, Jason Orendorff wrote:
>> 3. When a lambda yields, [...]
>> there may be other functions on the stack, in between. You can't
>> always statically tell which ones.  This means that generator
>> semantics affect the integrity of code that isn't in a generator.
>
> [...] this extends the finally integrity
> degradation outside of the lexical scope of the generator function. Good
> point.
>
>> [...] with generators+lambdas, almost any function call *anywhere* in the
>> program might never return or throw.  This weakens 'finally', at
>> least.
> [...]

> 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(g.next()); // tell the user the meaning of life, etc.
> g = null;
> gc();


Thanks all, this has been very clarifying. You both have put your
finger on what was nagging at me and explained it clearly.

It seems that either lambda or generators by themselves may be ok, but
together they make a fatal combination. Whichever we might eventually
decide to add to Harmony, we probably forever preclude the other. I do
not yet have an opinion on which.

-- 

    Cheers,
    --MarkM


More information about the es-discuss mailing list