Local functions

Mark Mahieu markmahieu at googlemail.com
Wed Feb 10 05:52:21 PST 2010


On 10 Feb 2010, at 13:09, Rémi Forax wrote:
> 
> There is a simple solution, if you want to write recursive function, 
> create a static method
> and reference it as a lambda:
> 
> class A {
>   static int factorial(int x) {
>     return (x<= 1) ? 1 : x*factorial.(x-1);
>   }
> 
>      public static void main(String[] args) {
>          #int(int) lambda = A#factorial;
>      }
> }
> 

I don't think that approach is quite so simple if your recursive function needs to use locals in the method which 'creates' it (eg. it references 'args' in 'main', in your example).

Regards,

Mark



More information about the lambda-dev mailing list