lua-users home
lua-l archive

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


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 right-side expression.

Just a thought...

--
chris marrin                ,""$,
chris@marrin.com          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"'