Local functions

Alex Buckley Alex.Buckley at Sun.COM
Wed Feb 10 11:26:22 PST 2010


Rémi Forax wrote:
> if you walk a tree, the method that walk is recursive, not the lambda 
> taken as argument.
> 
> simple solution => if its a complex lambda, write it as a method or as 
> an inner class then construct a lambda on it.
> 
> class A {
>   static int foo(String[] args, int x) {
>     return (x<= 1) ? args.length : x*foo.(x-1);
>   }
> 
>   public static void main(final String[] args) {
>     #int(int) lambda = #(int x) (foo(args, x));
>   }
> }

I'm glad you are also thinking about the limits of lambdas. I do not 
relish developers continually having to choose between putting code in a 
nearby method, a static nested SAM class, an anon.inner SAM class, or a 
lambda. Things used to be so simple...

Setting up a lambda expression as above is characterized as the 
"Closure/Stored message invokability principle" in 
http://blogs.oracle.com/ohrstrom/2009/08/using_methodhandles_to_reconci.html:

"A method reference like: MyApp#saveState() will be transformed into the 
closure { MyApp m ==> m.saveState() }  this is identical to the stored 
message (aka MethodHandle) #MyApp.saveState. "

Method references are in scope for this project, though I tend to think 
that relying on ordinary methods ignores Doug's plea for clear 
demarcation of (and restrictions on) code that experiences parallel 
execution.

Alex


More information about the lambda-dev mailing list