lua-users home
lua-l archive

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


On 23/02/2008, Roberto Ierusalimschy <roberto@inf.puc-rio.br> 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 <john.hind@zen.co.uk> 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.