Optional brackets around lambda expression
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Fri Jun 17 20:33:48 PDT 2011
Hi all,
to be crystal clear, i have to re-post my proposed syntax again.
seperate syntax for expresion lambdas and statement lambdas :
1) Expression Lambdas:
1.1) if len(args) <= 1: optional parentheses
[(] [arg0] [)] -> expr
sample1:
list.filter( t -> t.length() > 3 )
.map( t -> t.barCount )
.max();
sample2:
students.where(s -> s.degree > 10)
.select(s -> s.name); // .select(s -> list(s.name,s.degree ));
sample3: empty args
doRun( -> out.println("lambda"))
1.2) if len(args) > 1: required parentheses
(args ) -> expr
Sample:
Sam2<Integer,Integer,Integer> func5 = (x, y) => x * y;
2) Statement lambdas:
2.1) if len(args) <= 1: optional parentheses
[(] [arg0] [)] -> { statement* }
list.filter( t -> t.length() > 3 )
.map( t -> t.barCount )
.max();
doRun( -> { out.println("lambda"); })
2.2) if len(args) > 1: required parentheses
(args ) -> { statement* }
Sam2<Integer,Integer,Integer> func5 = (x, y) => { return x * y;};
Best Regards,
Ali Ebrahimi
On 6/17/11, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
> On 17/06/11 15:48, Bob Foster wrote:
>> Maurizio Cimadamore wrote:
>> >
>> > Of course you can lookahead; but certain expressions, as pointed out
>> > will remain ambiguous:
>> >
>> > process(x, y, z, a, b, c, d -> a);
>>
>> Assuming parenthesis are required for multiple arguments and optional
>> for single arguments, the example has only one parse, equivalent to:
>>
>> process(x, y, z, a, b, c, (d) -> a);
> I think we were discussing a proposed variant were parenthesis were
> optional all around (regardless of arity). If parenthesis are required
> only for arity > 1, then I agree with your analysis.
>
> Maurizio
>>
>> Bob
>
>
>
More information about the lambda-dev
mailing list