[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Globals vs. Locals
- From: "Vijay Aswadhati" <wyseman@...>
- Date: Fri, 5 Aug 2005 13:21:18 -0700
On Friday, August 05, 2005 10:49 AM, Mark Hambur wrote:
> Somewhat unpolished idea that just came to me when thinking about requiring
> globals in scripts to be declared. What if one could write something like:
> local for global table, string
> This would be equivalent to:
> global table, string
> local table, string = table, string
> This would encourage people to build scripts that cache global lookups in
> local variables.
C# provides an overloaded feature using the 'using'  keyword that is pretty
nice - sugar-wise; with some adaptation a feature like that provides a nice
balance and can solve to a certain degree the global versus local debate.
The usage might vaguely resemble like this:
<vaporware lua code>
-- illustration (1)
using ( table, string, ... )
-- any variable access in this block implicitly is
-- limited to those tables and variables specified
-- in the 'using' clause, which as per Mark's suggestion
-- get 'localized'.
-- illustration (2)
function foo(...) do
-- somewhere else, foo could be invoked like this:
foo (a1, a2, a3) using (table, string)
-- foo's access to variables are limited to those specified
-- in the using clause. And here the idea is that 'using'
-- clause is optional. If not specified foo has access to
-- pretty much what it can normally.
</vaporware lua code>
I wonder if something like this could be achieved using LHF's proposed
preprocessor and the setenv/getenv functions.
I was just trying out my 'syntax engineering' hat. I will remove it now ;-)