[swift-evolution] [Idea] Passing an Array to Variadic Functions

Brent Royal-Gordon brent at architechies.com
Mon Apr 18 14:55:40 CDT 2016


> I would like to see format strings go away and be replace with safer inline annotations.

The main problem is doing localized strings with printf-style formats well, but I actually have a pretty sweet solution for that: https://gist.github.com/brentdax/79fa038c0af0cafb52dd

> -- E, somewhat agnostic on variadics

Variadics are eventually important as a generic function feature; you really want to be able to write a version of zip() which can take any number of sequences, for instance, and the only reasonable way to do that is to pass a variable number of parameters and return a sequence with a matchingly variable number of type parameters.

Today, they are important in that they bootstrap ArrayLiteralConvertible and DictionaryLiteralConvertible by (at least theoretically) acting as a pass-N-items mechanism that doesn't depend on one of the standard library types defined in terms of it. (If we convert them to show up as tuples once we have tuple subscripting syntax, that will even become true.) Less esoterically, they're used in several places where an Array would be inconvenient or break traditions:

* The `print` function's list of items to print is variadic. An array equivalent would look like `print([one, two, three])`.
* The `min` and `max` functions are more convenient than explicitly constructing an array and calling their `min()` and `max()` methods.
* And, yes, `String.init(format:_:)`, which we will probably never be quite rid of for compatibility reasons.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list