<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><div id="AppleMailSignature"><div><span style="background-color: rgba(255, 255, 255, 0);">Hi Christopher,&nbsp;</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Do you think something like this would work if there was a #splat() magic operator like this:</span></div><span style="background-color: rgba(255, 255, 255, 0);"><br>let values = [1, 2, 3, 4, 5]</span></div><div id="AppleMailSignature"><span style="background-color: rgba(255, 255, 255, 0);">let mean = arithmeticMean(#splat(values))</span></div><div><br></div><br></div><div><br>On May 20, 2016, at 11:19 AM, Christopher Boyd via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><span style="line-height:1.5">Currently, Swift doesn't have a way to easily pass a variadic parameter to another variadic function because the variadic parameter itself has already been collected into an array.</span><br></div><div dir="ltr"><br>There was a prior posting a few weeks back about allowing arrays to be passed to a variadic parameter which would resolve this very specific issue:<br><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160411/015185.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160411/015185.html</a><br><br>Unfortunately, that thread devolved into an argument on whether or not variadic parameters should be removed entirely.<br><br>I, certainly, see merit in having functions that can accept a variable number of arguments and variadic functions should seem intuitive to anyone else that might be reading the code.<br><br><div>Swift's documentation presents a very intuitive example:<br><ol style="border:0px;font-size:14px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;font-family:helvetica,arial,sans-serif;background-image:initial;background-position:initial;background-repeat:initial"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">arithmeticMean</span>(<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">1</span>, <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">2</span>, <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">3</span>, <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">4</span>, <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">5</span>)</code></li></ol>It's obvious what this function is doing, and any intelligent person would expect 3 as the result.&nbsp; Even WolframAlpha knows how to interpret this:&nbsp;<a href="http://www.wolframalpha.com/input/?i=arithmeticMean(1,+2,+3,+4,+5" target="_blank">http://www.wolframalpha.com/input/?i=arithmeticMean(1,+2,+3,+4,+5</a>)&nbsp;<br><br>Moreover, a function can only have ONE variadic parameter, which I think reduces any possible confusion.<br><br>Regardless, if variadic parameters are going to stay in Swift, then I think they should at least support chaining to another function.<br><br>The most obvious way of allowing this would be to allow variadic parameters to accept an array.<br><br>However, I think that if an array (of the parameter type) is specified for a variadic parameter, then no other values should be allowed.&nbsp; This eliminates any unnecessary complexity of potentially having to add values to the array.</div><div><br></div><div>- Christopher Boyd</div></div></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>