How would shallow generators compose with lambda?

kevin curtis kevinc1846 at googlemail.com
Fri May 15 02:34:38 PDT 2009


If a function is used instead of a lambda, do the the same - syntactic
or semantic - problems arise?

 foo((lambda (x) yield x), arg);

to:

 foo((function (x) yield x), arg);  // js1.7 expression closure syntax
OR
 foo(function (x) { yield x}, arg);

On Fri, May 15, 2009 at 6:11 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On May 14, 2009, at 6:04 PM, Waldemar Horwat wrote:
>
>> Brendan Eich wrote:
>>>
>>> On May 14, 2009, at 1:47 PM, Waldemar Horwat wrote:
>>>>
>>>> This whole thing is another nail in the coffin of generators.
>>>>  Generators are the root of the troublesome longjmp's which don't play well
>>>> with others.
>>>
>>> Are you talking about generators, or lambdas?
>>
>> Generators.  They cause control flow to jump around between two
>> independent functions.
>>
>> THe same problem occurs without lambdas:
>>
>> function gen(arg) {
>> try {
>>  yield 1;
>>  yield 2;
>> } finally {
>>  alert("Finally called up to three times?!");
>> }
>> }
>>
>> That finally will be called either 1, 2, or 3 times depending on what the
>> caller does, which violates the principle that finally is called exactly
>> once, no matter how you leave a scope.
>
> Did you actually test this? Firefox 2 and up work the same.
>
> js> g = gen()
> [object Generator]
> js> g.next()
> 1
> js> g.next()
> 2
> js> g.next()
> typein:6: ReferenceError: alert is not defined
> js> alert=print
> function print() {
>    [native code]
> }
> js> g = gen(42)
> [object Generator]
> js> g.next()
> 1
> js> g.next()
> 2
> js> g.next()
> Finally called up to three times?!
> uncaught exception: [object StopIteration]
>
> Exactly one finally.
>
> /be
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list