[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Down with Upvalues
- From: ramsdell@... (John D. Ramsdell)
- Date: 31 Aug 2001 07:08:59 -0400
Edgar Toernig <email@example.com> writes:
> He? Of course they have nested scope. Or how would you call this?
Your example show code that demonstrates nested scoping, but the
following code shows that Lua variables lack nested scope.
1. function addn(x)
2. function sum(y)
3. return x+y -- illegal reference to x
5. return sum
If the variable x had nested scope, the scope of variable x would be
delimited by the function/end keyword pair. It would start at line 2,
and continue until line 5. With nested scoping, the reference to
varible x on line 3 would be legal.
Lua variables have either global or local scope. A locally scoped
variable is accessible only within the function in which it is
defined. Variable x is defined in addn, so its scope is not delimited
by the function/end keyword pair. All regions that define a nested
function are removed from its scope.
In summary, the existence of local scoping and nested functions means
that Lua lacks nested scoping.