Block lambda is cool, its syntax isn't

Brendan Eich brendan at
Thu Jan 12 14:49:18 PST 2012

> François REMY <mailto:fremycompany_pub at>
> January 12, 2012 2:23 PM
> Am I wrong if I say there not a bigger issue with block lambda than 
> with the current object notation on the matter?

Please continue :-).
> I mean, does that code mean anything useful?
>    function() {
>        {|a,b| a+b};
>    }

(You need a name for that function if it is a declaration, and from the 
context you show, it is.)

Does this perfectly valid JS mean anything useful?

   function f() {
     (function (a, b) { return a + b; });

Nevertheless, it is legal. JS follows C (not Java) in allowing seemingly 
useless expression-statements. This can be a source of bugs. It is also 
required in some cases, namely when the function expression (in 
parentheses) is the completion value of a Program. In such a case that 
value could be the wanted result of eval or an eval-like host API.
> If not (as it seems to me), it means that a block lambda will not be 
> used as a statement by itself. If it's the case, it should defined as 
> an Expression only,

Expression is already a kind of statement, via ExpressionStatement. 
Furthermore, an ExpressionStatement *already* cannot start with a left 
curly brace. Please read the grammar:

12.4 Expression Statement


ExpressionStatement :
     [lookahead ? {{, function}] Expression ;

NOTE An ExpressionStatement cannot start with an opening curly brace 
because that might make it ambiguous with a Block. Also, an 
ExpressionStatement cannot start with the function keyword because that 
might make it ambiguous with a FunctionDeclaration.

> where there's no anonymous block to conflict the syntax.

This is the conflict you're looking for.

> That solution has been chosen for object notation in the past. That way,
>    function() {
>        {
>            (a, b)
>            a.add(b)
>        }
>    }

That is already valid ES1-6.

Others have already replied, but the problem with redefining ( after { 
without untenable newline sensitivity is it is a backward-incompatible 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list