return when desugaring to closures

Brendan Eich brendan at mozilla.com
Wed Oct 15 18:13:17 PDT 2008


On Oct 15, 2008, at 2:36 PM, Waldemar Horwat wrote:

> There is no such thing as a "let expression".

Let expressions in JS1.7 (Firefox 2+), based on the ES4 proposal. ES3- 
ish grammar:

LetExpression :
       let ( VariableDeclarationList ) [lookahead ∉ {{}]  
AssignmentExpression

produced from PrimaryExpression.


> It's mandatory because the grammar and semicolon insertion rules say  
> so.  Btw, to properly terminate a lambda expression you'd need *two*  
> semicolons.  Here's why one would be insufficient:
>
> f = lambda(x) x;
> (a + b) && c;
>
> would parse the body of the lambda as the expression "x;", the "(a +  
> b)" as an argument to the lambda, and the rest as applying to the  
> result of calling the lambda.  What you'd want to write instead  
> would be:
>
> f = lambda(x) x;;

Expression closures in JS1.8 (Firefox 3+) do not have this problem.  
Using ES3's notation:

FunctionDeclaration :
       function Identifier ( FormalParameterListopt ) FunctionBody
FunctionExpression :
       function Identifieropt ( FormalParameterListopt ) FunctionBody
FormalParameterList :
       Identifier
       FormalParameterList , Identifier
FunctionBody :
       { SourceElements }
       [lookahead ∉ {{}] AssignmentExpression

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20081015/2ee03bbb/attachment.html 


More information about the Es-discuss mailing list