block lambda revival

Brendan Eich brendan at mozilla.com
Mon May 23 19:55:36 PDT 2011


On May 23, 2011, at 6:51 PM, Brendan Eich wrote:

> Done, at http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival -- this was easy, but it made me wonder whether parentheses for the plain Expression arguments that may occur after the leading BlockLambda ought not better be curly braces. IOW, instead of
> 
>   bar = foo {|x| x * x} (42);
> 
> support this:
> 
>   bar = foo {|x| x * x} {42};
> 
> This is more uniform on its own new terms. If the first actual parameter wants to be an expression, the programmer must parenthesize the entire argument list (comma separated of course), or else write {| | 42} as the first argument.
> 
> So, are curlies better than parens in this situation? I think it is a bit of a corner case, but good to address to avoid the currying hazard.

Silly of me, tempted by syntactic prettiness but this idea does nothing to address your objection.

But here is a grammar change, not too big (and required for yield expressions anyway) that does help:

[from http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax#grammar_changes]

Change all uses of AssignmentExpression outside of the Expression sub-grammar to InitialValue:

ElementList :        // See 11.1.4
    Elisionopt InitialValue
    ElementList , Elisionopt InitialValue
 ...
PropertyAssignment : // See 11.1.5
    PropertyName : InitialValue
 ...
ArgumentList :       // See 11.2
    InitialValue
    ArgumentList , InitialValue
 ...
Initialiser :        // See 12.2
    = InitialValue

InitialiserNoIn :    // See 12.2
    = InitialValueNoIn

Define InitialValue:

InitialValue :
    AssignmentExpression
    CallWithBlockArguments

Define CallWithBlockArguments:

CallWithBlockArguments :
    CallExpression BlockArguments

extend PrimaryExpression:

PrimaryExpression :
    ...
    ( CallWithBlockArguments )

And BlockArguments as follows:
BlockArguments :
    BlockLambda
    BlockArguments [no LineTerminator here] BlockLambda
    BlockArguments [no LineTerminator here] ( Expression )
The InitialValue non-terminal will also produce YieldExpression for generators, already in Harmony.

This is not nearly so bad as "significant surgery of nearly the entire expression stack in the grammar", but I may be missing something.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110523/229027e2/attachment-0001.html>


More information about the es-discuss mailing list