[Prev][Next][Index][Thread]

Re: Closures



Jeff Dalton wrote:
> I suspect the reason's the same as in Java (where you can do the Java
> equiv of closing over variables only if they're "final") - there's an
> easy implementation if you copy bindings instead of sharing them, and
> you can hide the semantic difference by forbidding assignment.

This is only true in Java for local variables.  Fields in a surrounding
scope are still shared and mutable.

It was never clear to my why this was done for Java.  It would not have
been very hard for the compiler to rewrite the function to replace local
variables with length-one arrays and then pass  those.  Whatever.



Follow-Ups: