[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefining locals
- From: "Aaron Brown" <aaron-lua@...>
- Date: Thu, 11 Nov 2004 11:50:14 -0500
Rich Artym wrote:
> I don't doubt for a moment that that's exactly how Lua
> scoping was meant to work, but it's not lexical scoping at
> all, but very normal dynamic scoping.
If Lua had dynamic scoping, the following program would
print "dynamic", but instead it prints "lexical":
do
local foo = "lexical"
function printfoo()
print(foo)
end -- printfoo
end
do
local foo = "dynamic"
printfoo() -- Prints the value of of the variable
-- referred to by foo when the function was closed,
-- not the foo that's here where the function's being
-- called. Whether that foo can be changed or is just
-- a snapshot or read-only is a different issue.
end
Incidentally, a colleague of mine just pointed out that Lua
4 had just the type of "snapshot" lexical scoping that
you're talking about.
(By the way, someone correct me if I'm wrong about Scheme
and Lua having exactly the same type of lexical scoping --
I'm not fluent in Scheme.)
--
Aaron