[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Implicit Globals - A (better?) compile time solution.
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 23 Feb 2008 10:20:37 -0300
Maybe a (partial?) solution to the implicit global problem would be to
follow the style of strict.lua, but at compile time. There would be
only one rule:
- an assignment to an "unseen" global inside a function raises a
"Unseen" means that that global has not been used before in that chunk.
To use a global inside a function, you may need to "declare" it. If the
global belongs to the chunk, a simple "name = nil" in the global level
will do. Otherwise you may use something like "name = name". It is
strange, but it is (or should be) uncommon for a function to mess with
globals declared elsewhere.
(Question: in "a = a + 1", should the second 'a' be a valid "declaration"
for the first one?)