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

Arthur Sabintsev arthur at sabintsev.com
Sat Dec 12 13:52:16 CST 2015


Hmm, a VariadicArray<T> sounds like an interesting solution, however, it would break existing implementation. I’m trying to avoid having to do that.

I think the previously discussed solutions, and/or your proposal for strict-typing (e.g., disallowing Any), are steps in the right direction, as they introduce new functionality without breaking existing implementations. 

Just my 0.02.

Best,

Arthur / Sabintsev.com

On December 12, 2015 at 2:39:26 PM, David Waite (david at alkaline-solutions.com) wrote:


> On Dec 12, 2015, at 12:12 AM, Arthur Ariel Sabintsev via swift-evolution <swift-evolution at swift.org> wrote:  
>  
> Thanks for your response.  
>  
> The reason this doesn't work is due to Swift's generic system as it allows a type T to be a anything, including arrays. The example that was used to delineate this concept to me was that of "Any...", which from within the variadic function, could be interpreted as T or [T]. The result is ambiguous in the current implementation, which is why some identifier syntax needs be passed along with an array to get this to work properly.  
>  
> As for the choice of operator, I'm open to suggestions. I wanted to use one that was familiar to other developers, so I chose the one that Ruby uses.  
>  
> Maybe a ~ would be better, or a keyword like @variadic?  
>  

I was thinking of a second type (VariadicArray<T>, perhaps) which you received in the body of your function instead of Array, and which was not supported via … sequence (so no args: VariadicArray<T>… allowed). However, it looks like this type would have to be fixed, not allowing for protocol compliance (including Any)  

Would it be possible to automatically take a function which uses T… and generate the [T] argument version of the function? Today, I just implement the [T] variant and have the T… function do nothing but call it.  

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


More information about the swift-evolution mailing list