|
As apealing as it looks, I wouldn't want to have such a syntax such as
local x,y from vector
The reason is, that this keyword seems useless to me beyond the purpose it was intended for (loading values from a table into the local scope).
What I like about Lua is that there are only a few concepts with a wide variety of applications. To me, this feature looks really neat - but not convincing.
I wonder however, if there exists a more general concept that would allow doing such things among other possibilities. What I was wondering was, if it would be possible to access the local scope in a table like way - which would effectively allow doing such imports. E.g.
----------
local x,y as s -- s would be a table like reference to this scope
s.x = 5 -- assigning a value to a key in s ...
print(x) -- would update the local value
import (s) : from (math) -- passing the scope to functions, which could do all kind of stuff
s.z = 1 -- runtime error, no such local
for k,v in pairs(s) do
ptint(k,v) -- print all locals from that table
end
local cos,sin,tan as m
from(math):import(m) -- different way
print(cos(0)) -- 1
local cos,sin,tan in import(math) -- import called with scope table for (cos, sin, tan) as first argument. A bit Similar to for cos,sin,tan in import
---------------
A scope object/table would be a special table - actually, this behavior could already be done using proxy tables and the debug api (though it'd look clumsy). The scope table could be obtained through such a keyword and it could be passed around. Such a concept would be somewhat similar to closures that allow you to modify certain locals - it would be just more general purpose.
But that's all not really so much needed, Lua is already pretty perfect I believe ;) (but access on locals this way would be really cool...)
Eike
On Feb 3, 2010 10:07 PM, "Luiz Henrique de Figueiredo" <lhf@tecgraf.puc-rio.br> wrote:> Many languages have quasi-keywords which are only reserved in some contexts.
So did Lua when "for ... in ... do ... end" was first introduced: "in"
was only recognized as reserved in that context.