lua-users home
lua-l archive

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

"Nick Trout" <> writes:

> Does that mean that Python (2.2) is not lexically scoped either
> because it also forces a closure? (but can look right to the outer
> level)

I'm quite puzzled by the description of Python's new scoping rule, but
here is my best guess as to what it is saying: A local variable that
is referenced by one or more functions defined within the block in
which the local variable is defined cannot be changed.  In Lua terms:
the following code is illegal because local a cannot be modified since
it is referenced by the function bound to foo:

        local a = 5
        local foo = function() print(a) end
        a = 10   -- Illegal under Python rules!

Even though this rule is more restrictive that Lua's rule, Python DOES
provide lexical scoping as functions defined within a block have
access to all the bindings made in the block.