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

A (un)splat operator for named arguments #203

Open
copumpkin opened this issue Jun 2, 2016 · 12 comments
Open

A (un)splat operator for named arguments #203

copumpkin opened this issue Jun 2, 2016 · 12 comments

Comments

@copumpkin
Copy link

What I'd like is for it to behave just like a regular function application, so:

local foo(x, y=100, z) = { x: x, y: y, z: z }

local bar = {
  x: 1,
  y: 2
}

foo(**bar) # Should return { x: 1, y: 100, z: 2 }

Going the other way would also be nice:

local foo(**kwargs) = kwargs

foo(x=6, y=1) # Should return { x: 6, y: 1 }
@sparkprime
Copy link
Contributor

sparkprime commented Jun 3, 2016

I've been wondering whether to just do Python semantics *args **kwargs or to instead have a ... keyword that encompasses both and is a bit cleaner.

@copumpkin
Copy link
Author

My general preference is for cleanliness over similarity to python, but others might feel differently 😄

@igorpeshansky
Copy link
Contributor

igorpeshansky commented Jun 3, 2016

The ... syntax will only cover declaring various forms of varargs, while (as I understood it) this FR was primarily about invoking a function with a programmatically constructed list of (possibly keyword) arguments.

@copumpkin
Copy link
Author

@igorpeshansky it's both, but yes, I certainly care about invoking more (since that's the one that's harder right now)

@igorpeshansky
Copy link
Contributor

I may be missing something, but how would the ... keyword be used to invoke a function?

@fkz
Copy link

fkz commented Aug 9, 2016

I don't understand your examples at all, what programming language are they even in and why should z be 2?

@fkz
Copy link

fkz commented Aug 9, 2016

arg sorry, I somehow got linked here from nix and thought I'm still in the nix thread...

@sparkprime
Copy link
Contributor

no worries :)

@DanielJoyce
Copy link

This would be killer for templating out config files....

@bbinet
Copy link

bbinet commented Nov 29, 2018

Same here, splat operators would be very useful.
Do you know of any workaround to call a function dynamically using arguments that are currently available as object fields?

@codesuki
Copy link

codesuki commented Oct 2, 2019

@bbinet did you ever find a solution?

@ghostsquad
Copy link

This would be quite useful. At the minimum, it would save me from having to wrap the variadic args in [].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants