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

Igor Bukanov igor at mir2.org
Mon May 18 11:53:54 PDT 2009

2009/5/18 Brendan Eich <brendan at mozilla.com>:
> On May 18, 2009, at 2:25 AM, Igor Bukanov wrote:
>> 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.
> You mean yield, not eval, right?

Right, that was a typo.

>> The plus side of this is that an empty generator can be created with a
>> straightforward:
>>  Generator(function() {})
>> and not with a rather unnatural
>>  (function() { if (false) yield; })()
> No one makes empty generators.

For me the problem with the way the generators are defined is that a
dead code like that "if (0) yield;" affects the semantic by mere
presence of it. Surely, this is not the first feature in ES that has
that property - "if (0) var a;" is another example. But "if (0)
yield;" sets a new record affecting the nature of the whole function.

> It doesn't need more runtime
> magic machinery and global constructors that are otherwise unmotivated.

That is true, but then runtime-only generators allows to avoid opt-in
tax for all the users. How high is that tax I do not know, but surely
it prevents some user cases for the feature.


More information about the es-discuss mailing list