lua-users home
lua-l archive

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


> in all other programming languages (that I know) variables in 
> subroutines/functions are automatically local. Is there a reason, why it 
> is implemented the other way round? 

I don't know the languages you know, but the languages I know don't behave
like that. In C, for instance, if you write

  void f (void) {
    i = i+1;
  }

this `i' is not "automatically local". If you want a local `i', you must 
say so. The same is true in C++, Pascal, Java, Perl, Ada, FORTRAN, Scheme, 
Simula, Smalltalk, SNOBOL, ML, Haskell, etc. etc. (Tcl is one of the few 
exceptions.) 

What is different from Lua to most of these languages is that, in most of 
these other languages, global variables must be declared before used. (The 
absence of a global declaration, however, doesn't turn them into locals! It 
just triggers an error.) With tag methods, you can make Lua triggers 
(run-time) errors about undeclared global variables if you want. 

-- Roberto