

there is probably nothing as funny as suggestions from a newbie  so
here is one:
if I got it right, an expression like t[1,2,3] is a syntax error.
would you find it reasonable if instead, whenever it meets a
commaseparated list as an index, lua would try to call the __index
(or __newindex) method of the metatable?


Pavol Severa wrote:
there is probably nothing as funny as suggestions from a newbie  so
here is one:
if I got it right, an expression like t[1,2,3] is a syntax error.
would you find it reasonable if instead, whenever it meets a
commaseparated list as an index, lua would try to call the __index
(or __newindex) method of the metatable?
This WILL happen if you do this:
t[{1,2,3}]

chris marrin ,""$,
[hidden email] b` $ ,,.
(650) 9419040 mP b' , 1$'
M1 ,.` ,b` ,` :$$'
,` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'$P ,"1$` ,b$P ,` :$1
b$` ,$: :,`` $$ ,` $$` ,` ,$$,,`"$$ .` :$
b$ _m$`,:` :$1 ,` ,$Pm` ` :$$,..;"' $:
P$b, _;b$$b$1" $$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'


On Mar 20, 2006, at 8:41 AM, Chris Marrin wrote:
This WILL happen if you do this:
t[{1,2,3}]
As a silly idea, to simplify the syntax, how about:
t{ 1, 2, 3 }
Where 't' is actually a closure function wrapping up a table of your
choosing?
function narray( ... )
 fill out your table here
 local _t =
return function( ... )
local indices = { ... }
local theObj = _t
for i=1,#indices do
theObj = theObj[ indices[ i ] ]
end
return theObj
end
end
local t = narray( 3, 3, 3 )
print( t{ 1, 2, 3 } )


Gavin Kistner wrote:
On Mar 20, 2006, at 8:41 AM, Chris Marrin wrote:
This WILL happen if you do this:
t[{1,2,3}]
As a silly idea, to simplify the syntax, how about:
t{ 1, 2, 3 }
Where 't' is actually a closure function wrapping up a table of your
choosing?
Or t can still be a table, whose metatable has a __call method. This
will call the method with a single table param. The question is what do
you want to do with this. If you say:
local a = t{1,2,3}
Then presumably you are dereferencing the table in some interesting way,
and the __call function can do that for reasonable results. But this:
t{1,2,3} = 12
is not legal Lua syntax. Unfortunately, a Lua function cannot return an
'lvalue' (in C nomemclature). Seems like it would be useful to allow a
function call to be on the left side of an assignment statement. By
default this:
f(a,b) = 12+14
could translate to:
f( {a,b}, {12+14} )
Using tables would make it easy to separate the input params from the
rightside expression.
Just a thought...

chris marrin ,""$,
[hidden email] b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'$P ,"1$` ,b$P ,` :$1
b$` ,$: :,`` $$ ,` $$` ,` ,$$,,`"$$ .` :$
b$ _m$`,:` :$1 ,` ,$Pm` ` :$$,..;"' $:
P$b, _;b$$b$1" $$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'

