Inverted syntax option
John Nilsson
john at milsson.nu
Thu Mar 11 11:37:17 PST 2010
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