[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: global
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Fri, 19 Apr 2002 19:32:14 +0200
Luiz Henrique de Figueiredo wrote:
>
> >bar = 10;
> >
> >fuction foo()
> >bar = 5; -- this bar is local to foo()
> >print(bar);
>
> How about "print"? Is it local too?
> --lhf
Hmmm... that is indeed a dificult question,
seen the way LUA works with variables.
In PHP, print would remain global because it is a
builtin function (what I would want). However, in LUA,
this would probably mean sacrificing orthogonality.
You would need to add another rule in the spirit of 'if
the variable refers to a builtin function, then it takes
precedence above local definitions'. Which may not a good
idea for LUA.
Still, I maintain that allowing function scope assignments to
overwrite global scope variables is a bad idea. If forces
programmers to know the name of all global variables and avoid
them, to prevent them from being changed unadvertently. I wonder
how the proposed global in ... statement brings adequate solace
for that problem.
I think I can sexplain my conundrum best with an example:
index = { "apple", "pear", "cherry" }
-- I want the table 'index' to be globally accessible
-- but without the hassle of saying 'global' every time.
foo = function()
-- I want foo also to be globally accessible without a hassle
index = 0
-- But I want this 'index' to be local, without the hassle
-- of having to say 'local' or such every time.
print(index)
-- And to top it off, 'print' is the global print
end;
Yes, I want to have my bread and eat it. Perhaps some kind of
'super-global' scope could work here?
--
"No one knows true heroes, for they speak not of their greatness." --
Daniel Remar.
Björn De Meyer
bjorn.demeyer@pandora.be