lua-users home
lua-l archive

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



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! :)

-asko


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
compile-time error.

"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?)

-- Roberto