[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Making Lua lexically scoped (was: Re: Proper tail recursion)
- From: ramsdell@... (John D. Ramsdell)
- Date: 27 Jul 2001 10:05:25 -0400
I went to http://lua.swiki.net/13 and read your page, and then
followed the reference it contains to a definition of lexical scope.
I quote from the link:
In a lexically scoped language, the scope of an identifier is fixed
at compile-time to be the smallest block (begin/end or
function/procedure body) containing the identifier's
declaration. This means that an identifier declared in some block
is only accessible within that block and from procedures declared
This definition is consistent with the one I gave, and also implies
that Lua is not lexically scoped. In Lua, an inner-function does not
have access to the local variables in the function in which it is
defined, it only has access to a COPY of those variables.
I don't understand your comment about how omitting set! from Scheme
would change the scoping rules of Scheme. Even without set!, a Scheme
inner-function has access to the variable bindings in the function in
which it is defined.
There are many good texts that describe lexical scoping. I happen to
be looking at "Structure and Interpretation of Computer Programs", by
Harold Abelson and Gerald Jay Sussman, second edition, page 30, at
this time. It's a good source of information on this subject.
"John Belmonte" <firstname.lastname@example.org> writes:
> Previously I had written a page of notes about Lua's scoping issues
> (http://lua.swiki.net/13). By your definition, if !set was removed from
> Scheme the resulting language would not be lexcially scoped. Granted Lua's
> lexical scoping is severely limited, but it is lexical scoping. Note that
> Python just added lexcal scoping to the language, and it does not allow
> rebinding just like Lua's upvalues.