[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [Feature Request] "Extended argument list"
- From: "Soni L." <fakedme@...>
- Date: Fri, 24 Jun 2016 13:56:18 -0300
Lua has multiple returns, but no way to use them inline with a function
call. I was wondering if something like these could be added:
First idea: `f(pairs(t), 1, 2, 3)`;
- +This syntax is currently illegal, so it wouldn't break old programs.
- +The `` clearly indicates how many return values to transpose into
- +Can limit varargs: with `f(pairs(t))`, `f` would only see the
first 2 values of the `pairs(t)` call, dropping the 3rd.
- -Makes it feel like you can use `f([x]pairs(t))` (variable x) when in
fact you can't.
Second idea: `f(pairs(t),,, 1, 2, 3)`;
- +This syntax is also illegal, so it also wouldn't break old programs.
- +While not obvious at first, the number of commas after the function
call indicate how many return values to transpose into arguments.
- Commas at the end of the call would still be illegal, this has
the caveat of not being able to limit varargs.
- Could be made so a single comma at the end means 2 arguments, as
we can already use `(f())` to limit the results to a single value. The
caveat is that commas at the end would mean ONE LESS than the number of
- ?This conflicts with the "implicit nil" patch, as the implicit nil
patch makes `f(pairs(t),,,1)` become `f(pairs(t),nil,nil,1)`.
- HOWEVER, this is more of an extension to the "implicit nil"
patch: the code `f(t,,,1)`, would become `f(t,nil,nil,1)`.
- -(Very) Prone to "silent" typos.
The former syntax is better than the latter (3 positive points and 1
negative for the former, 2 positive and 1 negative for the latter),
altho I expect more people to like the latter simply because it's
similar to implicit nil.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.