On Tue, Aug 10, 2010 at 2:54 PM, Everett L
Williams II
<rett@classicnet.net>
wrote:
Javier,
Local by default works if there are no globals, only explicitly
referred to external vars. In further reading Steve's reference, there
are lots of interesting ideas, but if I had to choose, I would use the
nonlocal idea for a Python change or the proposal of David Thomas found
at the bottom, and specifically for lua. What I don't like about that
is that it preserves globals, which just are not necessary. Of course,
I am not trying to maintain continuity. I'm trying to come up with a
solution that will eliminate a whole class of very difficult to
diagnose errors from the language. It also makes recognition absolutely
simple. If it does not have a prefix, it is local by definition. If you
find an error where you were depending on an external variable, and it
does not have a prefix, your problem is solved. I do believe that the
prefix should be assigned locally when the variable is imported, again
getting rid of a source for conflict that would be created by the use
of a default. If you want to allow imported variables to be fulfilled
at execution, then you provide a table with an entry that points to an
error, only resolved when proper assignment takes place.
I'd go the opposite way and require a special sigil character for local
variables. One thing that seems to be forgotten here is that functions
are also variables, so if you had to import all your variables in some
way, you would also have to import functions as well. Having
different rules for functions than regular variables would be a huge
mess. I have no issue with global variables, but it would help a great
deal if it was easier to distinguish between a local and a global by
directly looking at their usage... perhaps if local variables require
the use of a sigil character instead of relying on a declaration such
as "local"
-- assign 35 to local variable x
$x = 35
-- assign global x + local x to local y variable
$y = x + $x
-- assign global y = local y
y = $y