[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Making Lua lexically scoped (was: Re: Proper tail recursion)
- From: Reuben Thomas <rrt@...>
- Date: Tue, 31 Jul 2001 09:09:10 +0100 (BST)
> It also points out the dangers of using antediluvian sources:-) Very few
> meet the test of time. The question that I have is why do we need global
> variables. If the language becomes fully lexically scoped, then variables
> declared at the proper level will become visible at all levels below.
> Why build a separate table for global variables. Just seems unnecessary,
> time consuming, and a creater of more baggage to haul around.
Every file is a separate scope (you can declare locals at the top level, as
the file as a whole is a chunk), so if you had no globals, you wouldn't be
able to share values between files; dofile("foo") couldn't leave any values
in the namespace &c.
Of course, you could get around this by changing things so that the top
level of every file is the *same* scope, and I agree that it's arguable that
using locals at the top level (outside a function or block) doesn't look
like good style.
However, I suspect this would be difficult to compile, since local variables
are normally accessed by index; this relies on the compiler's knowing all
the locals in advance, which it can't if you allow multiple files to create
locals in the same scope.
--
http://sc3d.org/rrt/ | maxim, n. wisdom for fools