Unlimited number of positional arguments and keyword arguments support in functions and methods.
Is your feature request related to a problem? Please describe. Often we need to handle unknown amount of arguments in function call. But till now, we don't have any way to handle this behavior.
Describe the solution you'd like Syntax:
fun some(...args, ***kwargs)
{
# args: [...] Array
# kwargs {...} HashMap
}
Inspired from Python.
Additional context Syntax is not final yet. Suggestions are welcome.
Update: New syntax is now:
- [x] Positional arguments
...args(Updated with #153) - [ ] Keyword arguments
***kwargs - [ ] Array unpacking
[...[1,2,3], ...[5,6,7]] - [ ] HashMap unpacking
{***{"key": "value"}, ***{"key": "value"}}
I like ... for positional args better. Not sure how to do kwargs in that case though (...... just looks stupid)
Maybe ... for args and *** for kwargs?
I was thinking to use ... for unpacking objects.
Like [...[1,2,3], ...[5,6,7]]
Then it's even better, because there's a nice symmetry between variadic arguments and passing variable amounts of args into a function. Like:
fun call(f, ...args, ***kwargs) -> f(...args, ***kwargs)
fun call(f, ...args, ***kwargs) -> f(...args, ***kwargs)
Those number of stars looking weird to me.
Is it possible to use it also for unpacking objects like [...[1,2,3], ...[5,6,7]]?
And also {***{"key": "value"}, ***{"key": "value"}} this syntax.
The 3 *** is for symmetry with the 3 .... Also I don't think unpacking into lists and dicts is as important as into function calls because you can just do [1, 2, 3] + [4, 5, 6] while for function calls there is currently no way to do it at all. Not saying it's bad though
I like this unpacking syntax from Python and also rest/spread operator from JS. I know developers will love it.
I am convinced with you proposal of ... for positional arguments and *** for keyword arguments. Look fine to me! 👍🏼
Updated the issue description and added list of tasks to perform.
Next is keyword arguments!