Expression Closures as Compliment to Arrow Functions

Brendan Eich brendan at mozilla.org
Tue Mar 24 13:42:38 UTC 2015


Brendan Eich wrote:
>> var y = (a) => a ? f : x++ (1);
>>
>> evaluated (or is it syntactically valid at all)?
>
> The problem with expression closures is precedence inversion: you have 
> LowPrec ~~> HighPrec ~~> stuff ending with LowPrec. The particular 
> nonterminals are AssignmentExpression and PrimaryExpression.
>
> No such problem afflicts arrows, because they are low-precedence, in 
> fact AssignmentExpression alternative right-hand sides. So your 
> example here is a syntax error, because you are placing two assignment 
> expressions

I mean an assignment expression followed by a primary expression, of 
course. The `(a) => a ? f : x++` arrow is an assignment expression, the 
`(1)` is a separate expression. The `(1)` cannot be the actual parameter 
list for the arrow unless you parenthesize the arrow to make it be a 
MemberExpression (the highest precedence non-terminal that can be the 
callee in a CallExpression).

Precedence, whee!

/be

> next to one another with no operator or semicolon in between.




More information about the es-discuss mailing list