yield syntax (diverging from: How would shallow generators compose with lambda?)

Igor Bukanov igor at mir2.org
Mon May 18 02:25:12 PDT 2009

2009/5/17 Brendan Eich <brendan at mozilla.com>:
> One of the appealing (at least to me)
> aspects of Neil's suggestion was that it would avoid opt-in versioning
> required by reserving yield (which is used in extant web content, or was
> when we tried reserving it without opt-in versioning -- the particular use
> was as a formal parameter name, used as a flag not a function).

This yield-like-eval proposal also requires to have a special function
to create a generator since yield (as implemented in SpiderMonkey and
in Python) is used both to implement the yielding action and to
indicate that the function is a generator.

The latter is necessary as a call to a function with yield somewhere
in the body creates a generator, it does not execute one. For that
reason the compiler must know what yield means, it can not wait for a
runtime check.

The remedy for this is simple - the generator can be created using
explicit call like Generator(f, arg1, ... argN). This would turn any
function into a generator and would allow for runtime checks for eval.
The plus side of this is that an empty generator can be created with a

   Generator(function() {})

and not with a rather unnatural

  (function() { if (false) yield; })()


More information about the es-discuss mailing list