[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: proposal: explicit control of multiple value adjustment
- From: Duncan Cross <duncan.cross@...>
- Date: Wed, 5 Jul 2017 11:29:22 +0100
On Wed, Jul 5, 2017 at 10:32 AM, 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".
I made a related proposal a few years ago, where adding an ellipsis
"..." immediately before a comma (or a semicolon separating two values
in an array-style table literal) to retain the full value list instead
of truncating it, for example:
--
local function multival() return 1, 2, 3 end
call(multival()..., 4, 5, 6)
local a,b,c,d,e,f = multival()..., 4, 5, 6
t = {multival()...; 4; 5; 6}
--
...in each case the full list would be 1, 2, 3, 4, 5, 6. Of course the
syntax gets a little weird when used with the OTHER use of "...", for
example to have a function that returns whatever arguments are passed
to it with one additional value appended:
--
function appendo(...)
return ... ..., "appended"
end
print(appendo("the", "final", "value", "is"))
--
It also doesn't include the option to fix the exact number of values,
as your proposal does.
-Duncan