Inverted syntax option
Alex Buckley
Alex.Buckley at Sun.COM
Fri Mar 12 04:18:41 PST 2010
I would call these "naked lambdas" since the expression with #
parameters is shorn of a signature or delimiters like {..}. But you
still have to pay the cost of a static type system, by casting the
positional parameters in order to do anything interesting with them.
This seems like an original, but really quite painful, idea.
Alex
John Nilsson wrote:
> Most syntax proposals so far has been variants of specifying the type and
> arguments of the lambda to be created. I have another suggestion, inverted
> lambdas.
>
> My suggestion is to focus on the current expression syntax of Java and just
> tweak it a little bit to allow parameters. So any valid Java expression is a
> lambda if it contains an identifier of the form #<n> where <n> denotes the
> position in the argument list.
>
> Examples. (I have borrowed Neals type syntax, but my suggestion is just
> about the expression syntax)
>
> (int,int) -> int adder = #1 + #2;
>
> int sum = intList.reduce(adder);
> int sum2 = intList.reduce(#1 + #2);
>
>
> When the type of an identifier is not known it defaults to Object
>
> Object expr = #1.method(); //Compiler error, method is not a member of
> Object
> Object expr2 = ((MyClass)#1).method(); //Typical cast already known to
> Java-developers.
> Object expr3 = ((MyClass)->Void) #1.method(); //This is also valid version
>
>
>
> BR,
> John
>
More information about the lambda-dev
mailing list