[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Globals (more ruminations)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 15 Jul 2010 13:04:47 -0300
> "global checks" as a statement doesn't "turn on" global assignment
> checking? Global assignment checking would be always on? Or is this
> simply how it works at the file chunk level? (Perhaps a new thread
> discussing the new change is warranted like the earlier "a new
> proposal for environments" thread. It would be most helpful to have an
> authoritative description of the proposed design.)
There is a good chance that this proposal will not go into 5.2; but
anyway, just to make it clear:
- there is a new keyword "global" that can be used in the same places
that "local" can be used (namely "global function ..." and
"global a,b,c...").
- "global function foo ..." expands to "global foo; foo = function ..."
(just like "local function" does).
- Names declared with "global" follow the same scoping rules of
names declared with "local", in the same name space.
- Any use (access and assignment) of "a" in the scope of a "global a"
declaration is translated to "_ENV.a".
- Any access to a free "a" (that is, outside any declaration for "a")
is translated to "_ENV.a".
- Any assignment to a free "a" that is outside the scope of any
other global declaration is translated to "_ENV.a".
- An assignment to a free "a" that is inside the scope of another global
declaration is an error ("attempt to assign to undeclared variable
'a'").
-- Roberto