Proposal: paren-free function calls and definitions

Brendan Eich brendan at mozilla.com
Sun Jun 19 16:37:10 PDT 2011


On Jun 19, 2011, at 4:04 PM, Brendan Eich wrote:

> On Jun 19, 2011, at 3:17 PM, Claus Reinke wrote:
> 
>> https://github.com/clausreinke/jstr/tree/master/es-discuss
>> 
>> You can find there the proposal text, with motivation, grammar changes, semantics (entirely via desugaring to existing syntax), and related issues, as well as a prototype implementation, using jstr's nascent grammar-based ES-to-ES rewriting:
>> 
>>   tailnests.txt: proposal text
> 
> 
> Quick reply to point out that:
>     FunctionExpression :
>       function Identifier_opt ( FormalParameterList_opt ) { FunctionBody }
> +     function Identifier_opt ( FormalParameterList_opt ) => AssignmentExpression
> 
> inverts precedence, as MemberExpression : FunctionExpression but now FunctionExpression can end with a low-precedence expression (AssignmentExpression).
> 
> For example, the last line in
> 
>   function f(x) => x;
>   z = a + function (b) => b ? f : x++(1);
> 
> parses awkwardly, as ( z = ( a + ( function (b) => ( b ? f : ( x ++ ) ) ) (1) ) ).

This is not just awkward, of course -- the grammar you propose is ambiguous. The precedence inversion means there are two ways to parse

  z = a + function (b) => b ? c : d;

Either as

  z = (a + (function (b) => b)) ? c : d;

or as

  z = a + (function (b) => (b ? c : d));

And we've been around this block before. Ambiguous grammars are future-hostile.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110619/71b569b2/attachment.html>


More information about the es-discuss mailing list