[Idea] Passing an Array to Variadic Functions


(Michael Peternell) #1

Regarding the original proposal:

I like the idea. I think it would be nice to allow the application of variadic args from an array. The syntax I could think of is:

let args = ["World"]
printf("Hello %s", *args)

So, "*" just converts "[a,b,c]" into "a,b,c", that's the idea. What do you think? (I don't suggest that this should also be used for dynamically dispatching overloaded methods, but if it would work, I would not complain :wink: .) Syntactically, it is no breaking change, and could also be introduced after Swift 3 has been released. From the perspective of the ABI, I don't know.

Regarding the removal of varargs:
No way, -100 from me. Just because you don't like a feature, doesn't mean it should be banned. I, for example don't like certain { curly brace } styles, but that doesn't mean that I would be happy if the only curly brace style that the language allows would be my style. Maybe my tastes change in a year or two. And for things like `sprintf`, I think variadic args are really helpful. In Objective-C, I use them for example for logging, having a function signature like NSString's stringWithFormat:. In that case, having to put a @[ bracket ] around all log arguments would be bad. And writing LogMe(@"it's done.", @[]) looks weird too!

-Michael