[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why are people so afraid of globals?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 10 Jul 2010 18:17:55 -0300
> Say there were a new statement of the form:
>
> global var1, var2, var3
>
> This would mean that we want to access the given names from the environment for the chunk.
>
> Global declarations like this would have the same precedence in lookup as locals. Hence,
>
> [...]
>
> One could then compile code with the insistence that all variables be
> declared as either local or global.
>
> But now we can use this in conjunction with the _ENV variable
> techniques to create alternate global environments. When such an
> environment is in place -- i.e., a specific _ENV declaration has
> superseded the chunk environment -- then variable names that cannot
> be resolved as declared locals or globals are resolved as elements of
> _ENV.
We were discussing something similar to this a few days ago, but without
this last part. That is, global declarations would simply control
whether the sugar "x" for "_ENV.x" is valid. Any "global" declaration
in a chunk would turn on the "insistence" that all variables be
declared.
Another point is weather all global should be declared or only those
being assigned. The point is that access to globals are much less
harmful and much more frequent (e.g., all standard libraries).
-- Roberto