[swift-evolution] Proposal for Passing Arrays to Variadic Functions

Joe Groff jgroff at apple.com
Sat Dec 12 13:56:01 CST 2015


> On Dec 11, 2015, at 10:54 PM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
> 
> You can't use * as suggested, because that conflicts with * as a prefix operator.
>  
> You could probably get away with using a trailing ... in the call, as in
>  
> func foo(xs: [Int]...) {
>     bar(xs...)
> }
>  
> I also wonder whether there's a reason Swift doesn't already support this. Maybe there's some desired future change to variadic arguments to improve performance (i.e. to avoid having to allocate an array) that wouldn't be compatible? Although I'm not sure what that would be. Maybe there's actually no barrier at all and it was just something that wasn't prioritized. It would be good to know either way.

No fundamental reason, just haven't gotten around to it. We are however planning to rework the type system model for functions not to be tuple-based, since it causes problems with unconstrained polymorphism, default arguments, inout parameters, and other function features. We'll need a replacement feature to support forwarding argument tuples if we do this. cc'ing Chris Willmore, who has been working a plan here.

-Joe

> -Kevin
>  
> On Fri, Dec 11, 2015, at 10:43 PM, Arthur Sabintsev via swift-evolution wrote:
>> Hi,
>>  
>> I have put together a proposal for passing arrays to variadic functions (along the lines of Ruby’s Splay operator). 
>>  
>> Proposal: https://github.com/ArtSabintsev/swift-evolution/blob/master/proposals/array-variadic-function.md <https://github.com/ArtSabintsev/swift-evolution/blob/master/proposals/array-variadic-function.md>
>> Pull Request: https://github.com/apple/swift-evolution/pull/52 <https://github.com/apple/swift-evolution/pull/52>
>> Bug Report: https://bugs.swift.org/browse/SR-128 <https://bugs.swift.org/browse/SR-128> which led to this proposal
>>  
>>  
>> Best,
>>  
>> Arthur / Sabintsev.com <http://sabintsev.com/>
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>  
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151212/8da69617/attachment.html>


More information about the swift-evolution mailing list