Recursive lambdas
Neal Gafter
neal at gafter.com
Mon Feb 22 07:35:21 PST 2010
On Mon, Feb 22, 2010 at 2:20 AM, Alex Buckley <Alex.Buckley at sun.com> wrote:
> The ability for a lambda expression to reference itself during
> initialization is noted in the 0.1.5 spec draft, but not actually
> specified. However, the answer is clear: the value of a variable of
> function type is a reference. fac.(...) makes reference to the lambda
> instance resulting from evaluation of #(int x)(x<=1...). This holds
> whether fac is a local variable or an instance variable. As always,
> extravagant aliasing is best avoided.
>
The first example is illegal because the body of the lambda uses a variable
that is not effectively final. But presuming it were legal (or marked with
"shared" or annotated with @Shared, or whatever)...
I thought that after you reassigned a variable, evaluating an expression
that is a reference to the variable should reflect the new value of the
variable. That is true whether or not the variable is declared inside a
lambda, outside a lambda, or as a field. Your response seems to suggest
some other semantics of variable assignment and variable reference.
More information about the lambda-dev
mailing list