lua-users home
lua-l archive

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


The problem I have with implicitly-local declarations is this:

In Lua, you can declare a local that shadows something higher up.
Another local or a global.

If Lua instead had implicit local declarations, you'd need to declare
identifiers you'd want to refer to globals in a higher scope.

Imagine:

global a, b, c
a = 3

You don't know if a is actually a global (in _G) or part of _ENV, or
just local from a higher scope.  From what discussion I've seen --
people have only been considering flipping the scoping rules.  If this
were done, we'd need a few more keywords to precisely identify which
scope we're connecting identifiers to -- such as:

global a -- connects to _G.a
main b -- connects to _ENV.b
upvalue c -- connects to the "nearest" 'c' identifier of higher scopes

>From what I've learned, the Lua community represented on this list is
hostile to new identifiers.  You could just use _G and _ENV to refer
to global and environmental scope all the time -- `up c' would ~work~.
These are just things to think about.  In some ways it would be more
readable because you would know for certain where you intend to modify
a "global" (in a liberal sense of the word).  I think Python has these
keywords because "global scope" is not a data structure you can modify
like a table would be in Lua.  I am not a Python person -- correct me
if I'm wrong.  I am entirely undecided on which scoping ideology I
prefer.