[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Implicit Globals - A (better?) compile time solution.
- From: Asko Kauppi <askok@...>
- Date: Sun, 24 Feb 2008 00:19:06 +0200
Sounds very good; my vote is "a = a+1" would be valid declaration if
it's at the chunk level (not within a function). Keep the rules simple.
The problems anyways come at the enclosed levels, not at chunk. This
covers both the need for interactive globals and the safety needs of
real code both at once. Splendid! :)
Roberto Ierusalimschy kirjoitti 23.2.2008 kello 15:20:
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
To use a global inside a function, you may need to "declare" it. If
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
for the first one?)