[swift-evolution] [pitch] Variadic Arguments should accept Arrays

Haravikk swift-evolution at haravikk.me
Sun Mar 12 04:08:04 CDT 2017


> On 12 Mar 2017, at 04:33, Ricardo Parada via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I read Haravikk's proposal a second time. I think I see the advantage of being able to use it with other types besides array. 
> 
> I also found disambiguating with the trailing comma to be intuitive. On the other hand I did not find it so intuitive to use @variadic and @nonVariadic to disambiguate.  I would say just pick the trailing comma. 

As written you'd be able to do both, it's just down to personal preference which. However, while the comma works fine for enforcing a variadic call, there does still need to be a way to tell Swift you want to call with an array, which is what the nonVariadic attribute/compiler directive is for; fortunately this is a case that only comes up when the function accepts elements of type Any, so there's ambiguity as to whether you're passing an array of elements, or an element that happens to be an array.

There are some other features being discussed where it might make sense to have an expansion operator, and some have proposed using the trailing ellipsis for this, so we could end up with something like:

	let bar = myFunc(foo...) // call as an array
	let baz = myFunc(foo,) // call variadically

But I'm just not sure if it's worth doing only for the single proposal or not? I suppose I could mention it in alternatives though!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170312/9e3b5276/attachment.html>


More information about the swift-evolution mailing list