Summary: Lambda syntax
Howard Lovatt
howard.lovatt at gmail.com
Thu Mar 18 19:30:45 PDT 2010
Hi Stefan,
Great summary of the various syntaxes. For my proposal, your B8, I think a
description that fits my 'intent' is:
Proposes two lambda definitions: lambda expressions and statements. Types
are optionally inferred by the diamond operator.
LambdaExpression:
new # < *TypeList* ( *ParameterList*opt ) *Exceptions*opt > ( Expression )
new # < *TypeList* ( *ParameterList*opt ) *Exceptions*opt > Block
new # < *IdentifierList*opt > ( Expression )
new # < *IdentifierList*opt > Block
*IdentifierList*:
*Identifier**
** Identifier, **IdentifierList
*
Examples:
new #< int() > (7);
new #< void(Event e) > { handle(e); };
new #< String(File f) > { return f.getName(); };
new #< #< R() throws E >( #< R( A ) throws E > l, A a ) >
( new #< R() throws E >()( l.( a ) );
new #<> ( 7 );
new #<e> { handle(e); }
new #<f> { return f.getName(); };
new #<l, a> ( new #<> ( l.(a) ) );
I carefully said 'intent' above, since my original post was just a quick
email and not a formal specification (therefore your description was
correct!). The reason for including the diamond operator, is like the rest
of the proposal, for consistency with the rest of the language. It would be
very odd if diamond were used for type inference for generics and a
different mechanism for lambdas. Note: the use of diamond follows on for the
argument for diamond itself; the argument for diamond is that it is
consistent with the current generic inference for methods. I
also assume that the diamond operator would be equally as applicable to
Gernot Neppert's, A14, variation (which is absent from section B).
In the examples, section A, how about arrays, e.g.:
#<String(File) throws IOException>[]
and section B:
new #<String(File) throws IOException>[]
new #<>[]
Excellent summary,
-- Howard.
More information about the lambda-dev
mailing list