lua-users home
lua-l archive

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

On 2006-11-09, Javier Guerra <> wrote:
> Mark Hamburg wrote:
>>     column{
>>         spacing = 10,
>>         $makeChildren(),
>>         view{
>>             title = "footer",
>>         }
>>     }
>> Where the $ means that we take all of the results from the function rather
>> than just the first. 
> i'd prefer to have it the other way around, that is using all values by 
> default.

I'd actually prefer it never using all the values by default, as it
currently sometimes (but not always) does.

How about extending the ... syntax?

    foo { bar = 1, ... = fn(), baz = 2 }


    a... = fn()


    a = { ... = fn() }

Or perhaps also

    foo { bar = 1, fn() ..., baz = 2 }

(although postfix "operators" may not be such a good idea).

You could then also allow for naming the "vararg" structure
with a similar syntax:

    function foo(bar, opts...)

         for k, v in ipairs(opts) do whatever end


Likewise you could call a function, expanding a table. You could
even support non-integer fields going into the vararg structure as
named parameters (although that may not be so simple with ... no
longer being a table):

    function foo(bar, opts...)

        if opts.quk then whatever end


    foo({1,2,3, quk = true}...)

	=> bar = 1, opts={2,3,quk=true}

Or maybe, to simplify things, an expanded table should always be
the vararg table, and maybe there could be just one of them in
a function call.