lambda syntax tutorial

Rémi Forax forax at univ-mlv.fr
Thu Aug 5 02:38:48 PDT 2010


Le 04/08/2010 18:47, Maurizio Cimadamore a écrit :
> Hi,
> since most of the features are available in the compiler, I took the 
> time to write a pretty basic syntax document/tutorial that shows the 
> syntax supported by the current lambda prototype. As usual, the 
> document does *not* imply that the currently implemented syntax is 
> also the final one - the aim of this document is to simply help 
> developers working with the lambda prototype.
>
> Thanks
> Maurizio

Hi,
see my comment at the end of this mail.

>
> Really Provisional Syntax for Lambda Project: August 2010
> Maurizio Cimadamore
>
> This document is a rather informal and basic guide on the syntax currently implemented in the lambda prototype.
>
> 1. Lambda expressions
> ---------------------
>
> Lambda expressions starts with the special '#' character.
>
> #() { ... }
> # { ... }
>
> Note: a nil-ary argument list can be omitted.
>
> 1.1 Formal parameters
>
> The formal parameters accepted by a lambda expression are enclosed in parenthesis (as with method declaration):
>
> #(int x, int y) { ... }
> #(x, y) { ... }
>
> Note: the type of a lambda parameter can be omitted - in this case the compiler will infer a type from the target type of the lambda conversion.
>
> 1.2 Body
>
> The body of a lambda expression can be either (i) an expression or (ii) a statement list (terminated by a ';').
>
> # { System.out.println("Hello"); System.out.println("Lambda!"); }
> #(int x, int y) { x + y }
>
> 1.3 Target-type
>
> A target-type can be explicitly selected using the following syntax:
>
> Mapper<Integer, String>  #(x){ x.toString(); }
>
> Note: the explicit target-type syntax can be handy in case of overload resolution.
>
> 2. Exception transparency
> -------------------------
>
> Exception type-parameters are declared using the 'throws' keyword:
>
> class Foo<throws X>  { ... }
>
> 2.1 Disjunctive Types
>
> An exception type-parameter can be instantiated by a disjunctive type, a list of reference types separated by a '|' char:
>
> Foo<Exception1 | Exception2>
>
> The nil-ary disjunctive is denoted using the keyword 'void':
>
> Foo<void>
>
> Note: 'void' is allowed as an actual type-argument only in correspondence with exception type-parameters.
>
>
> 3. Defender Methods
> -------------------
>
> Defender methods are declared using the 'extension' keyword, as follows:
>
> extension List<T>  map(Mapper<T>  r) default Collections.<T>listMapper;
>
> A defender method declaration is structured in two parts, (i) a method signature, declaring formal arguments, formal type-arguments and return-type and (ii) a default implementation, that is, the implementation the method should default to if none is found in the class implementing the extended interface.
>
>
> 4. Method References
> --------------------
>
> The syntax for method references uses the infix '#' operator; the selector of a method reference can be either a valid Java expression or a type:
>
> Foo#bar()
> new Foo()#bar()
>
> 4.1. Actual Arguments
>
> The actual argument type list associated with a method reference is optional:
>
> Foo#baz
>    

I think you can't do that because inserting an overloading method
is a source backward compatible change.

With this syntax, inserting an overloading method may break method 
references.

> However, if required, actual argument types can be specified after the method references, enclosed in parenthesis, as in:
>
> Foo#baz(Integer, String).
>
> Note: the explicit syntax can be handy in case of overload resolution.
>    

In my opinion, explicit syntax should be the only existing one.

Rémi




More information about the lambda-dev mailing list