lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I don't like the scoping rules either.  I brought this issue up last year 
and even when as far as modifying the scoping rules myself.

The combination of the following attributes makes it difficult to do 
large projects and cause typo bugs that are hard to find:
1. creating variables by assignment
2. variables inside functions defaulting to global (this is the worst one 
in my opinion).
3. having undefined variables be equal to NIL

The two options I thought of are
1. just make variable assignment default to local inside functions
2. require declaration of all globals and locals inside functions

Both options break old code though.  So the would need to be a 
variable_mode or a new "function" keyword.  The second option kind of 
goes against the "easy to write code" model of lua.  Option one coupled 
with requiring all locals to be declared (as it is now) is the best solution.
Assigning to something not declared as local or as an arguement would be 
an error.


On Fri, 4 Jun 1999, Freek Brysse wrote:

> > 
> > I have personally tested  lua, perl, python, tcl by writing
> > similar scripts. I found lua to be much faster (sorry cannot quantify
> > !!).
> > But the thing that really made me embrace lua is the sheer elegance
> > of the language.
> Lua is great on almost every point, except the scoping rules. Why can't we
> have normal scoping rules (i.e a variable is local unless defined
> globally?).  Though I read the rationale behind that decision somewhere, I
> wasn't exactly statisfied by it. 
> Is there any who likes these scoping rules?
> Are there any plans on changing this?
> Freek B.