Josh beat me. In any formal definition of closure, it is clear and explicit 
that a closure fully captures the static environment. There's no restriction 
to mutation of bindings in the captured environment, not even in SICP where 
the language is Scheme and the authors have a strong bias towards functional 
purism even though they are not radical about it (but maybe because that was 
before developments like Haskell's monads).

Of course, it can be argued that capturing the full environment vs. 
capturing only the variables that the closed function actually needs, is 
implementation detail. This is true as long as the language does not support 
dynamic lookup of variables - Java doesn't, despite reflection; we can't 
inspect the frames of the call stack and look up local variables by name or 
by any other means. But the restriction of doing only by-value capture is 
not orthogonal with a language that allows destructive assignment (and for 
Java, "allows" is an understatement; that's its primary paradigm). Nobody in 
lambda-dev disputes this in the conceptual level; Oracle's only reasoning to 
not allow capture of mutable variables is the red herring of concurrency 
(i.e. closures will be very useful in concurrent/asynchronous frameworks and 
developers are too stupid to mix that with mutable capture, even with a 
modifier to make such captures explicit). 

A+
Osvaldo

On Monday, September 12, 2011 4:40:40 PM UTC-4, Josh Berry wrote:
>
> On Mon, Sep 12, 2011 at 3:32 PM, clay <[email protected]> wrote:
> > A closure is when you define a function that "closes" over the local
> > environment from which the new function is defined and can access
> > local variables of that defining scope. Java absolutely does this.
>
> The problem being that the local environment for the function you are
> in in Java gets destroyed when you return from the function.  The
> compiler will copy over final values into the new environment that you
> create with an anonymous class, but the environment that exists as you
> create this instance gets destroyed.  (Hence, requiring that any
> variables exposed to the "closure" be final.)
>
> That is, if we had true closure (even without first order functions),
> you could declare two of them that communicated through a mutable
> variable.  Correct?  (This is a legitimate question, not a rhetorical
> trick.)
>
>

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/javaposse/-/klJ2yydI7t0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to