lua-users home
lua-l archive

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


On 5 July 2017 at 11:32, Viacheslav Usov <via.usov@gmail.com> wrote:
I propose adding a way for the user to say "I want to adjust to this number values" and "I want to pass all of them". While syntax is debatable as ever, something like this could work:

For function calls, allow an optional "adjuster" in the form :n, where n is either a number or *, meaning "n values" and "all values" correspondingly. Then the examples above could be re-written as follows:

bar(foo():2)
qux(foo():*, bar())

For vararg expressions, a similar adjuster could be used, even though it looks quite strange, so better syntax is probably possible:

bar(...:2)
qux(...:*, bar())

A slightly modified version of your proposal could be achieved without language change by extending select() to allow a table as the first argument, selecting which arguments you want to pick:

select({1,2}, foo())

This is a bit more generic than your proposal, since it also allows you to reorder arguments:

select({2,1}, foo())

But at the same time it does not allow for passing multiple arguments *after* the "adjusted" ones:

qux(select({1,2}, foo()), bar()) -- no language change, would still pass first value from foo()