On May 14, 2009, at 2:38 PM, Brendan Eich wrote:

Indeed the low-precedence (same as assignment) nature of the yield unary caused JS1.7 to follow Python in requiring parentheses around yield expressions in lists: in comma expressions and actual parameter lists (although we diverged from Python by allowing an unparenthesized yield expression as the last actual argument in a call or new expression's parameter list -- Python requires foo((yield bar)) instead of foo(yield bar)).

I have this idea that it would be better for yield expressions to look like function calls: 'yield' '(' expression? ')'. (Note that this is only a syntactical suggestion; clearly an implementation wouldn't actually treat it like a function.) That would eliminate the precedence issues Brendan cites while also making the syntax backward compatible with earlier ES parsers. Is there any technical reason why that wouldn't be possible?

Perhaps the "looks-like-a-duck, quacks-like-a-cow" objection would apply here -- a corner-case thingy that looks like a function but isn't should be avoided. But I have to say, in practice the required parenthesizing around yield expressions in JS 1.7 is an eyesore I'd like to see go away.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to