lua-users home
lua-l archive

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


Chris,

I would say that reasoning from 1200 lines of code on a shared memory language might not give assurance to those interested in scope problems that scope changing isn't a problem. Your summary of globals is one of the more succinct ones that I have seen, but I am not sure that it fully represents the case. I certainly would like for modules and all other code to have to be explicit about what goes off world and what comes in, but I don't see that either is fully accomplished in what is in the new work4. And, just promoting items into a global name space doesn't really solve most of the problems that globals cause.

Rett



Chris Babcock wrote:

I'm new to Lua, but most of my current site is written in CRM-114, which is a shared memory language - unscoped. As soon as I had learned to use that language and had about 1200 lines in production, someone introduced a fork with lexical scope. This was a source of a great deal of anxiety and the fork did break a couple of scripts, but I tested it and ended up using it. This situation isn't terribly different from that one except that Lua has a few million more users. :)

My understanding of this change here is that it operates on the mechanics of the way scope is implemented in the VM, but not the way it behaves in user space... except to apply some fairly intuitive limits to global variables initialized in modules. The result should be improved module safety with a limited amount of code overhead for packagers. Lua will still be global by default, but global now means global to an environment rather than global to an instance of the interpreter. Addressing variables in that environment will be transparent for module users, but packagers will need to be explicit about what goes 'off-world'.

As for the 'example'... Scope will still nest. The environment for the nested chunk is the same as the environment where the local was defined. No change. Sigils and any other thread of conversation spawned from a fear of scope changing is reasoning from a faulty premise.

Signoff
Chris

Ignoring antichrist references from my Android phone.

On Aug 10, 2010 10:01 AM, "Javier Guerra Giraldez" <javier@guerrag.com> wrote:

On Tue, Aug 10, 2010 at 11:57 AM, Everett L Williams II
<rett@classicnet.net> wrote:
> All declarati...

you're forgetting that 'local by default' simply doesn't work with
lexical scoping.  the final result would be something like what David
mentioned

--
Javier