[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Making Lua lexically scoped (was: Re: Proper tail recursion)
- From: Reuben Thomas <rrt@...>
- Date: Mon, 30 Jul 2001 13:50:56 +0100 (BST)
> I though that I understood what "lexically scoped" means, but I am not sure
Yes, I think some confusion has arisen.
As I understand it, "lexical" scoping is a term used in opposition to
"dynamic" scoping, i.e. whether an identifier's value arises from its inmost
enclosing textual definition (as in C, Pascal &c.), or from its most
recently executed enclosing function (as in LISP, BBC BASIC &c.).
local x = 2
local x = 1
c = function ()
Under dynamic scoping, the example above will print 2, because x's local
definition scopes dynamically over a's callees. Under lexical scope it'll
print 1, because x is bound by the textual (lexical) enclosing definition in
Of course Lua allows neither at the moment, because local variables are not
visible inside function definitions (except via upvalues). Nevertheless, Lua
is lexically scoped: you can tell because if you run the simpler example:
local x = 2
x = 1
you get 1, because a's x is not visible in b.
What proponents of "full lexical scoping" are really asking for might be
better described as "full closures", i.e. closures in which the free
variables are not fixed (but only bound) at instantiation time, and in which
you don't need special syntax to access them.
http://sc3d.org/rrt/ | Academics age by degrees