Project Lambda: Java Language Specification draft

Zdenek Tronicek tronicek at fit.cvut.cz
Wed Jan 27 12:47:46 PST 2010


Neal Gafter napsal(a):
>> However, one must ask here: what is the proposed
>> freedom
>> motivated by? And will not it blur the semantics?
>
> It is motivated by a desire to allow a compiler to, for example,
> statically allocate a lambda that captures no state.  For example, the
> lambda expression
>
> #()(3)
>
> can be statically allocated by the generated code, even if it appears
> in an inner loop.  That relieves the programmer from having to invent
> a variable to store the lambda and move it out of the loop himself.

Of course, this is a perfect motivation. But, for me, it is so natural as
if the compiler extract assignment to x out of the loop:

int x;
for (int i = 0; i < 10; i++) {
  x = 42;
  System.out.println(i);
}

The desugaring I mentioned should viewed as description of semantics. Not
prescription to the compiler.

Z.
-- 
Zdenek Tronicek
FIT CTU in Prague



More information about the lambda-dev mailing list