Summary: Lambda syntax
Stefan Schulz
schulz at the-loom.de
Thu Mar 18 16:09:44 PDT 2010
So I summed up the proposed lambda syntaxes, hopefully picked all of
them from the list. The summary is below, and the nicer to read document
version is as before at the following URL:
http://docs.google.com/View?id=ddhp95vd_15gqnv8xqm
In case of mistakes or missed proposals, let me know.
Cheers,
Stefan
0. Common syntax
Block:
{ BlockStatements }
BlockStatements:
BlockStatement
BlockStatements BlockStatement
BlockStatement:
LocalVariableDeclarationStatement
ClassDeclaration
Statement
ParameterList:
Parameter
Parameter, ParameterList
Parameter:
Type Identifier
1. Straw-man, latest
Proposes two lambda definitions: lambda expressions and statements.
Return type is inferred and throws meant to be transparent.
LambdaExpression:
# ( ParameterListopt ) ( Expression )
# ( ParameterListopt ) Block
Examples:
#() ( 7 );
#(Event e) { handle(e); }
#(File f) { return f.getName(); };
#(#R(A)(throws E) l, A a) ( #() ( l.(a) ) );
2. Rémy Forax, 05 Jan 2010
Proposes to use a keyword lambda instead of #.
LambdaExpression:
lambda ( ParameterListopt ) ( Expression )
lambda ( ParameterListopt ) Block
Examples:
lambda() ( 7 );
lambda(Event e) { handle(e); };
lambda(File f) { return f.getName(); };
lambda(#R(A)(throws E) l, A a) ( lambda() ( l.(a) ) );
3. Peter Levart, 26 Jan 2010
LambdaExpression:
# ( ParametersListopt ResultParameteropt ) Block
ResultParameter:
: Parameter
Examples:
#(: int i) { i = 7 };
#(Event e) { handle(e); };
#(File f : String s) { s = f.getName(); };
#(#(A: R throws E) l, A a : #(: R throws E) c) { c = #(: R r) { r =
l.(a); }; };
4. Peter Levart, 1 Feb 2010
LambdaExpression:
# ( ParameterListopt -> ReturnTypeopt ) Block
Examples:
#(->int) { return 7; };
#(Event e -> void) { handle(e); };
#(File f -> String) { return f.getName(); };
#(#(A -> R throws E) l, A a
-> #(-> R throws E)) { return #(->R) { return l.(a); }; };
5. Neal Gafter, 9 Feb 2010
LambdaExpression:
( ParameterListopt ) -> Expression
( ParameterListopt ) -> Block
Examples:
() -> 7;
(Event e) -> { handle(e); };
(File f) -> { return f.getName(); };
((A) -> R throws E l, A a) -> () -> l.(a);
6. BGGA
LambdaExpression:
{ ParameterListopt => BlockStatementsopt Expressionopt }
Examples:
{ => 7 }
{ Event e => handle(e); };
{ File f => f.getName() };
{ { A => R throws E } l, A a => { => l.(a) } };
7. Peter Levart, 2 Mar 2010
LambdaExpression:
( ParameterListopt -> BlockStatementsopt Expression )
Examples:
( -> 7 );
( Event e -> handle(e); void };
( File f -> f.getName() );
( (A -> R throws E ) l, A a -> ( -> l.(a) ) );
8. Howard Lovatt, 11 Mar 2010
LambdaExpression:
new #< Signature > ( BlockStatementsopt Expression )
Signature:
ReturnType ( ParameterListopt ) Throwsopt
Examples:
new #< int() > (7);
new #< void(Event e) > (handle(e); null);
new #< String(File f) > (f.getName());
#< #< R() throws E >( #< R( A ) throws E > l, A a ) >
( new #< R() throws E >()( l.( a ) );
9. C++ (via Stephen Colebourne), 14 Mar 2010
(translated to lambda-use)
LambdaExpression:
[ Accessorsopt ] ParameterDeclopt ReturnTypeDeclopt {
BlockStatementsopt }
ParameterDecl:
( ParameterList )
ReturnTypeDecl:
-> ReturnType
Accessors:
&
=
Closings
Closings:
Closing
Closing, Closings
Closing:
& Identifier
Identifier
this
Examples:
[] { return 7; };
[] (Event e) { handle(e); };
[] (File f) { return file.getName(); };
[] (R (*l)(A), A a) { return []{ return l.(a); };
10. Rémi Forax, 14 Mar 2010
LambdaExpression:
( ParameterListopt ) ( Expression )
( ParameterListopt ) Block
Examples:
() ( 7 );
(Event e) { handle(e); }
(File f) { return f.getName(); };
(R(A)(throws E) l, A a) ( () ( l.(a) ) );
11. Peter Levart, 17 Mar 2010
LambdaExpression:
( ParameterListopt : Expression )
{ ParameterListopt : BlockStatements }
FunctionInvocationExpression:
FunctionTypedExpression [ ExpressionListopt ]
Examples:
(:7);
{ Event e : handle(e); };
{ File f : return f.getName(); };
( [ A : R throws E ] l, A a : (: l[a]) );
More information about the lambda-dev
mailing list