lua-users home
lua-l archive

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

On 9/4/06, John Hind <> wrote:
As a long-time user of Lua in an environment where multiple scripters
share a common global table (Girder 4), there is just one thing in Lua
I'd really like to see changed. This is the automatic creation of
variables in the global environment table.


I think this is a bad idea. Consider this example:

function f()
 function g()
   a = 1
 a = 2

With your proposed change, would the two "a"s refer to the same
variable, or would each assignment introduce a new one? I don't think
there's an easy and elegant way to make a compiler do the first (and
it would make the language specification much more convoluted), and
the second looks really ugly (this is not exactly, but related to one
of my biggest problems with PHP).

There's also the "problem" of functions already mentioned. I guess it
could be resolved by saying that "function f()..." is really "global
f; function f()..." -- although I must confess that, coming from a
Scheme background, I don't like this arbitrary separation of functions
and variables.

I really prefer the forced declaration ("option explicit") you
mentioned to resolve this "issue", i.e., don't allow reading from
variables without a previous assignment. I believe this can be done
currently by munging the global environment metatable.
I would take it a step further: don't allow ANY use of undeclared
variables, and make it a compile-time check (like Perl's "use
strict"). But this would introduce the need of a keyword ("global") to
declare global variables.

PS: I've been reading this list for some time, but this is my first
message. Please excuse my bad english.