Nannying (was: Array comprehension syntax)

Allen Wirfs-Brock allen at
Tue Sep 25 15:23:08 PDT 2012

On Sep 25, 2012, at 1:30 PM, Brendan Eich wrote:

> Allen Wirfs-Brock wrote:
>> I think we should go the all AssignmentExpression route.  It avoid ArrayLiteral-like comma confusion in all three positions.  It is also a simpler set of rules to teach and remember. 
> It's different from the statement forms, though.

The statement form of if is already different in that parens are required.  If you have the AssignmentExpression restriction on the paren-feree comprehension if clause a parenthesized comma expression would still be valid and look exactly like the statement form. 

> Again, this is a non-issue in practice. Nobody writes comma expressions in those places.
>>   Finally, it leave open the future possibility of ArrayLiterals that have comprehensions in element positions. (not that I'm recommending this...) 
> Why wouldn't comprehensions be allowed in ArrayLiteral element positions? That falls out of any grammar that puts comprehensions at PrimaryExpression precedence, where they must be.

Just to be clear about what I meant... I can imagine in the future somebody proposing an extension to ArrayLiteral that would permit something like:
  let a = [0,  n for n in range(1,10) if !(n%2), 100];
which produced similar array to [0,1,3,5,7,9,2,4,6,8,10,100].

If ES6 permits Expression in if clauses this would be incompatible change.

Like you say, it's not a big deal and not necessarily an extension that I would be a fan of.

> This is not a huge deal and I defer to Jason as champion-apparent, but it does seem worth agreeing on the same Expression non-terminal for if and for conditions in both statements and comprehensions, or finding a better reason to change in the latter.
> /be

More information about the es-discuss mailing list