Implementing recursive lambda with MethodHandle

Neal Gafter neal at gafter.com
Mon Feb 22 08:26:19 PST 2010


On Mon, Feb 22, 2010 at 3:52 AM, Rémi Forax <forax at univ-mlv.fr> wrote:

> How to implement solution 2 or 3 with method handles ?
> First, it's not simple because a method handle is an
> object that contains a function pointer to a method,
> so there is no dedicated class.
>
> You have to first create the method handle and then inject itself to be
> available
> in the body of the function referenced.
> Because injecting the method handle creates a new method handle
> so you have a eggs and chicken problem that you can solve with an array.
>
> Rather ugly, isn't it ?
>

Sure is ugly.  As a practical matter, I'd expect the compiler to use a frame
object rather than an array, as it would for @Shared variables, but it's
still ugly.  I have two suggestions to address this:

(1) Don't make "this" refer to the function from within the function.  That
minimizes how often the compiler would do this.
(2) Don't look at the generated code. ;-)

Cheers,
Neal


More information about the lambda-dev mailing list