Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlimited number of positional arguments and keyword arguments support in functions and methods. #152

Open
1 of 4 tasks
Almas-Ali opened this issue May 31, 2024 · 11 comments
Labels
enhancement New feature or request
Milestone

Comments

@Almas-Ali
Copy link
Member

Almas-Ali commented May 31, 2024

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:

  • Positional arguments ...args (Updated with Add variadic arguments from #152 #153)
  • Keyword arguments ***kwargs
  • Array unpacking [...[1,2,3], ...[5,6,7]]
  • HashMap unpacking {***{"key": "value"}, ***{"key": "value"}}
@Almas-Ali Almas-Ali added the enhancement New feature or request label May 31, 2024
@angelcaru
Copy link
Contributor

angelcaru commented May 31, 2024

I like ... for positional args better. Not sure how to do kwargs in that case though (...... just looks stupid)

@angelcaru
Copy link
Contributor

angelcaru commented May 31, 2024

Maybe ... for args and *** for kwargs?

@Almas-Ali
Copy link
Member Author

I was thinking to use ... for unpacking objects.
Like [...[1,2,3], ...[5,6,7]]

@angelcaru
Copy link
Contributor

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)

@Almas-Ali
Copy link
Member Author

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]]?

@Almas-Ali
Copy link
Member Author

And also {***{"key": "value"}, ***{"key": "value"}} this syntax.

@angelcaru
Copy link
Contributor

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

@Almas-Ali
Copy link
Member Author

Almas-Ali commented May 31, 2024

I like this unpacking syntax from Python and also rest/spread operator from JS. I know developers will love it.

@Almas-Ali
Copy link
Member Author

I am convinced with you proposal of ... for positional arguments and *** for keyword arguments. Look fine to me! 👍🏼

Almas-Ali added a commit that referenced this issue May 31, 2024
@Almas-Ali
Copy link
Member Author

Updated the issue description and added list of tasks to perform.

@Almas-Ali
Copy link
Member Author

Next is keyword arguments!

@Almas-Ali Almas-Ali added this to the v0.1 release milestone Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants