How would shallow generators compose with lambda?

David-Sarah Hopwood david-sarah at
Thu May 28 12:32:40 PDT 2009

Brendan Eich wrote:
> I think we missed an alternative that comports with Tennent's Oversold
> Correspondence Principle, *and* composes. Thanks to Dave Herman for
> pointing it out.
> function gen(x) {
>   foo( lambda (x) (yield x*x) );
> }
> need not yield from gen if the lambda is called from foo or another
> function -- it can throw the same error it would throw if the lambda
> escaped upward/heapward and was called after gen had returned. There's
> no requirement that yield not throw in any case where the lambda is not
> applied in the context of gen.

Well, that depends on what lambda is expected to be used for.

If it is expected to be used to implement general user-defined control
structures, then this restriction would prevent a yield from appearing
in the body of any such structure.

For the use of lambda in built-in expansions, OTOH, this would probably
be adequate, assuming the check that the lambda is called from the body
of the generator function is applied *after* expansion.

David-Sarah Hopwood  ⚥

More information about the es-discuss mailing list