How would shallow generators compose with lambda?
Brendan Eich
brendan at mozilla.com
Fri May 15 12:22:20 PDT 2009
On May 15, 2009, at 2:34 AM, kevin curtis wrote:
> If a function is used instead of a lambda, do the the same - syntactic
> or semantic - problems arise?
No, because yield in a function makes it a generator, whereas in the
lambda proposal extended to treat yield as return/break/continue are
treated (per Tennent's Correspondence Principle), yield does not make
the lamda some kind of generator-lambda -- instead it yields the
nearest enclosing function (if active; else throw).
> 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);
That passes a generator function to foo. If foo calls it, foo gets a
generator-iterator, which if used in a for-in construct, or explicitly
iterated via .next/send/throw, yields x once then throws StopIteration.
/be
More information about the es-discuss
mailing list