On 15.05.2011 10:33, Brendan Eich wrote:
On May 13, 2011, at 11:25 PM, Brendan Eich wrote:
I'll update
http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax
to include an ES5 grammar patch.
Done:
http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax,
specifically
http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax#grammar_changes
This requires splitting the sub-grammar starting at Expression (comma
expression), at AssignmentExpression (which occurs in all
comma-separated list non-comma-expression contexts, namely argument
lists and initialisers), creating a parallel production chain from
Statement through AssignmentStatement.
Many languages restrict assignment to statement form. We don't need to
do that and shouldn't break extant code that nests assignment
expressions, but separating assignment statements (comma-separated
lists of assignments) enables better right-hand side syntax for arrow
function expressions -- namely, they don't have to be parenthesized.
Thus you can write
array.map((elem) -> elem * elem)
let identity = (x) -> x;
thrice = (x) -> 3 * x;
without gratuitous parenthesization. Calling an arrow function
expression requires parentheses on the outside, of course:
alert((-> "paren me")());
Comments welcome, I haven't had time to formalize and test this but it
looks like it will work.
Cool!
// Use # to freeze and join to nearest relevant closure
function return_pure() {
return #(a) -> a * a;
}
let p = return_pure(),
q = return_pure();
assert(p === q);
So, ES3 joined-objects are back. Though, the question is in their
[[Scope]] difference (i.e. can be they joined in the following case):
let foo = (args...) -> {
return #(a) -> args.map(a);
};
foo(1, 2, 3)((x) -> x * x); // [1, 4, 9]
foo(5, 10)((x) -> x * x); // [25, 10]
Do both have the same (reflected) [[Scope]] to be joined? At first
glance with named args, e.g. foo(a, b, c) yes, but what's with rest args?
Other things seems fine.
Dmitry.
/be
Grammar Changes
Change all uses of /AssignmentExpression/ outside of the /Expression/
sub-grammar to /InitialExpression/:
ElementList : // See 11.1.4
Elisionopt InitialExpression
ElementList , Elisionopt InitialExpression
...
PropertyAssignment : // See 11.1.5
PropertyName : InitialExpression
...
ArgumentList : // See 11.2
InitialExpression
ArgumentList , InitialExpression
...
Initialiser : // See 12.2
= InitialExpression
InitialiserNoIn : // See 12.2
= InitialExpressionNoIn
Define /InitialExpression/ and /ArrowFunctionExpression/:
InitialExpression :
AssignmentExpression
ArrowFunctionExpression
ArrowFunctionExpression :
FormalParametersOpt Arrow [lookahead ∉ {{}] InitialExpression
FormalParametersOpt Arrow Block
FormalParameters :
( FormalParameterListOpt )
Arrow : one of -> or =>
Split assignment out of /ExpressionStatement/ into /AssignmentStatement/:
Statement :
Block
VariableStatement
EmptyStatement
AssignmentStatement
ExpressionStatement
...
AssignmentStatement :
[lookahead ∉ {{, function}] AssignmentList ;
AssignmentList :
Assignment
AssignmentList , Assignment
Assignment :
LeftHandSideExpression = InitialExpression
LeftHandSideExpression AssignmentOperator InitialExpression
ExpressionStatement :
[lookahead ∉ {{, function}] ConditionalExpression ;
Finally, /PrimaryExpression/ produces a parenthesized
/ArrowFunctionExpression/:
PrimaryExpression :
...
( ArrowFunctionExpression )
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss