Optional brackets around lambda expression
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Mon Jun 20 02:12:52 PDT 2011
Hi,
And this is full grammar:
LambdaDeclaration =
LambdaParameterList '->' LambdaBody
LambdaParameterList =
LambdaParameter? | '(' ( LambdaParameter ( ',' LambdaParameter )* )? ')'
LambdaParameter =
Parameter | Identifier
LambdaBody =
Expression | `{' Statement* `}'
Ali Ebrahimi
On Mon, Jun 20, 2011 at 12:34 PM, Ali Ebrahimi
<ali.ebrahimi1781 at gmail.com>wrote:
> Hi Maurizio,
> Exactly, with two differences:
> 1)
> "->" instead of "=>"
>
> 2)
> C# does not allow this: process( -> 10 + 10 ) or process( -> { return 10
> + 10; } )
> In C# for nillary args parentheses is required and should be: process( ()
> -> 10 + 10 ) or process( () -> { return 10 + 10; } )
>
> I think for this case avoiding parentheses is readable and cleaner.
>
> Best Regards
> Ali Ebrahimi
>
> On Mon, Jun 20, 2011 at 11:42 AM, Maurizio Cimadamore <
> maurizio.cimadamore at oracle.com> wrote:
>
>> Isn't this similar, if not identical, to the C# syntax?
>>
>> Maurizio
>>
>>
>> On 18/06/11 04:33, Ali Ebrahimi wrote:
>>
>>> 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<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