[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Implicit Globals - A (better?) compile time solution.
- From: "Mark Meijer" <meijer78@...>
- Date: Sat, 23 Feb 2008 18:25:26 +0100
On 23/02/2008, Roberto Ierusalimschy <email@example.com> wrote:
> Maybe a (partial?) solution to the implicit global problem would be to
> follow the style of strict.lua, but at compile time.
I think that's what I said.
On 23/02/2008, John Hind <firstname.lastname@example.org> wrote:
> It seems to me that the key is to treat implicit *assignment* differently
> from implicit *reference* as the latter is relatively harmless. If change
> your suggestion so that the first *assignment* to a global raises an error
> unless explicit, but then allow further assignment within that chunk, that
> would certainly go a good way.
> So (assuming a is not already a local):
> --start of chunk
> a = a + 1 -- Error: attempt to assign to global 'a' without explicit
> reference: use _G.a
I certainly don't hope the _G.myglobal syntax is going to be required.
I prefer the explicit forward declaration way. Sure, _G sticks out,
and that's because it's ugly. Forward declarations stick out well
enough and are much nicer and cleaner, imho.
Also, I think what you want is to handle initialization differently.
Not assignment. And reference (in the sense you meant it) is only
harmless if the variable has already been initialized. The forward
declaration approach handles this nicely.