Reified Lambda Functions

Alex Blewitt alex.blewitt at gmail.com
Thu Jan 7 07:09:01 PST 2010


On Jan 7, 2010, at 14:27, Howard Lovatt wrote:

> Thanks for pointing these mistakes out. I have updated the proposal  
> in response, see section 2.

:-) Nothing like putting something on the TODO list ...

#_R_(_A_ _N_) (_E_)
Which creates a new lambda instance


I think terminology here could do with some thought, but there's not  
been much discussion on it when proposed:

http://mail.openjdk.java.net/pipermail/lambda-dev/2009-December/000136.html

Specifically, is this creating an instance, or just defining a lambda?  
If it doesn't capture any information (e.g. an identity function)  
should the compiler be free to promote it to some kind of permanent  
instance (e.g. pulling it up to be statically defined and/or lazy  
instantiated singleton)? Using 'instance' here might be misleading if  
only because logically, the lambda might or might not be instantiated  
at that point depending on what the lambda body is/does.

Of course, from a semantic point of view, this is just defining a  
lambda, and one shouldn't confuse the semantics with the  
implementation optimisations that may or may not be used ...

I'd propose changing this to 'defines a lambda (expression)' since  
this might not be confused with (anonymous) object instantiation.

Similarly, the title in 5.1 talks about 'lambda instances' and there  
explicitly defines them to be 'new $Callable$'. We might want to  
define them as 'equivalent to' but note that the compiler may be free  
to avoid the instantiation each time if the result of that  
instantiation would be equivalent to keeping a cached version.

(This in turn leads to a question - if such a lambda is used once,  
would keeping it around defeat the purpose of being able to garbage  
collect the type? would a weak reference to a singleton be a better  
implementation detail?)

Alex


More information about the lambda-dev mailing list