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

Brendan Eich brendan at mozilla.com
Mon May 18 10:25:50 PDT 2009


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?


> 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.

I think this cure is worse than the disease! The problem of yield's  
precedence can be solved by mandating parenthesization as Python does  
-- or if ugliness prevails, as Neil proposes :-P. It doesn't need more  
runtime magic machinery and global constructors that are otherwise  
unmotivated.

/be


More information about the es-discuss mailing list