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

proposal: make variadic function take arguments in a more flexible way #60163

Closed
stephane-archer opened this issue May 12, 2023 · 1 comment
Closed

Comments

@stephane-archer
Copy link

stephane-archer commented May 12, 2023

In the following code:

func Greeting(prefix string, who ...string) {
}

// classic parameter passing
Greeting("nobody")
Greeting("hello:", "Joe", "Anna", "Eileen")

s := []string{"James", "Jasmine"}
// ... parameter passing
Greeting("goodbye:", s...)

Greeting("goodbye:", append([]string{"Kevin"},s...)...) // work but is not really convenient 
Greeting("goodbye:", "Kevin", s...) // is not working but would be nice

basically the ... operator can represent an "unpacking operation" and the compiler can see that Greeting("goodbye:", "Kevin", s...) doesn't break the prefix string, who ...string signature.

I hope this is clear
I think this would not break backcompatibily and make things nicer when working with variadic function

@gopherbot gopherbot added this to the Proposal milestone May 12, 2023
@seankhliao
Copy link
Member

Duplicate of #18605

@seankhliao seankhliao marked this as a duplicate of #18605 May 12, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
@golang golang locked and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants