lua-users home
lua-l archive

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


["Dr. Rich Artym" <rartym@galacta.demon.co.uk>]
> On Thu, Nov 11, 2004 at 02:00:09PM -0600, Matt Hellige wrote:
> 
> > I agree. There is absolutely no doubt that Lua is a textbook example
> > of lexical scoping. The behavior that Rich is talking about is
> > implemented, for example, in Java's inner classes, where it is
> > universally hated. The Java implementation is generally considered an
> > implementation shortcut taken to avoid having to implement true (or at
> > least traditional) lexical scoping. 
> 
> Java is a static language, so I'm not sure what its relevance is here.
> I'm coming to this from the point of view of functional programming.
> 
> The two languages that Roberto and I are comparing are Lua and Scheme,
> but the concept of closures is quite independent of any specific language.
> Closures are all about ..... closure.  The word really means what it says.

Quite simply, you're wrong. Try this example in SML (which I'm sure
you're comfortable with, since it's a functional language):

    - val x = ref 5;
    val x = ref 5 : int ref
    - fun inc_x () = x := !x + 1;
    val inc_x = fn : unit -> unit
    - x;
    val it = ref 5 : int ref
    - inc_x();
    val it = () : unit
    - x;
    val it = ref 6 : int ref
    - x := 10;
    val it = () : unit
    - x;     
    val it = ref 10 : int ref
    - inc_x();
    val it = () : unit
    - x;
    val it = ref 11 : int ref
    -

Updateable variable, as in Lua, are equivalent to reference cells in
SML, not values. Your understanding of the meaning of closure is
simply incorrect. 

Matt


-- 
Matt Hellige                  matt@immute.net