Transparancy

Brian Goetz brian.goetz at oracle.com
Wed Jul 7 11:26:06 PDT 2010


> - this is still scoped to the lambda

Yes, that's true.  In fact, a better way to think about these lambda 
expressions is that they are really "SAM expressions".  They are often more 
compact than CICE (since the target type can be inferred) but lambdas do not 
(at this time) stand alone.

> The problem with the approach is that it is schizophrenic. The
> previous approach with "this" and "return" had a certain consistency
> such that it was the same as an inner class. Since this proposal is
> *more* like CICE (simplified inner classes), one would have expected
> to have seen both "this and "return" remain. Instead "yield" appears
> completely at random.

It is indeed *more* like CICE (and therefore an inner class), it is really 
something in between.  The quibbling over the semantics of return are a 
reflection of trying to force lambdas to either be exactly like inner classes 
or something completely new.  The reality is that they are somewhere in the 
middle.  Using "return" now complicates our ability to provide nonlocal 
control flow in the future.

> As is well known, I believe strongly that 'this' should be lexically
> scoped. Its just so much the standard for closures in other languages
> that IMO it is quite amazing that anything else is actually being
> considered.

If you were designing a language from scratch, you would almost certainly take 
that path.  But adding features to a mature language like Java without 
breaking either compatibility or the mental model of the 12M existing users 
requires taking into account all the decisions that have been made so far, and 
often leads you to places that you would never get if you started with a blank 
sheet of paper.



More information about the lambda-dev mailing list