lua-users home
lua-l archive

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


On Thu, Nov 11, 2004 at 09:13:01AM -0500, Aaron Brown wrote:

> local foo = 1 
> 
> function incrementfirstfoo()
>   foo = foo + 1
>   print(foo)
> end -- incrementfirstfoo
> 
> local foo = 1
> 
> print(foo) -- prints 1
> incrementfirstfoo() -- prints 2
> print(foo) -- prints 1
> incrementfirstfoo() -- prints 3
> print(foo) -- prints 1
> incrementfirstfoo() -- prints 4
> print(foo) -- prints 1
> incrementfirstfoo() -- prints 5
> print(foo) -- prints 1

Nope, that wasn't an example of it.  The function modifies the "foo"
inside its own closure which is an entirely different scope, not the
"foo" in the old scope that was obsoleted by the second "local foo".

Rich Artym.
-- 
Existing media are so disconnected from reality that our policy debates
spin around a fantasy world in which the future looks far too much like
the past.   http://www.zyvex.com/nanotech/MITtecRvwSmlWrld/article.html