Brendan Eich wrote: > On May 17, 2009, at 6:39 PM, Neil Mix wrote: >> - we could always allow parenthesis to be dropped when the yield is >> the entire expression of an expression statement or the right-hand >> side of an assignment. > > Right-hand side of assignment is ok without parens in Python because > assignment is a statement. > > In JS if you allow assignment expressions ending in unparenthesized > yields, then you can have unparenthesized yields in argument and > initialiser lists, comma expressions, and in the middle and final > operand positions in ternary (?:) expressions. > >> - in my experience with JS 1.7 I almost always had to parenthesize the >> yield expression when it was in some other kind of expression. An in >> the cases where parenthesis weren't required, I parenthesized anyway >> to avoid ambiguity and maintain coding style consistency. (And >> because I got tired of predicting incorrectly whether or not parens >> would be required in a particular context.) > > The only contexts we allow you not to parenthesize in JS1.7 are > assignment expressions and final argument in list. But see above -- the > assignment expression loophole is big enough to allow > > foo(a = yield b, c); > > One argument, or two?
*If* it is allowed, then it should be two. It would be very surprising if foo(a = b, c); had two arguments (as it does), but the above expression with yield had one. But I agree that it may be better not to allow it. >> So I would argue that there are two syntactical forms of yield, yield >> E and (yield E), and that the rules regarding the requirement for >> parenthesis are hard to predict (from personal experience). >> Therefore, I argue that it would make sense to simplify a bit: >> - the yield E form may be used when it is the entire expression of an >> expression statement >> - all other times it must be parenthesized > > Agreed; this closes the assignment expression loophole. This would disallow foo(yield x); which seems unnecessary. -- David-Sarah Hopwood ⚥ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

