<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>+1 from me as well. I have no problem with the function declaration in the example. It's very intuitive and is much more elegant than destructing in the function body.</div><div><br></div><div>Cole</div><div><br>On May 6, 2016, at 2:05 AM, Goffredo Marocchi 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><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>+1 it improves readability a lot and thus should be encouraged.<br><br>[[iOS messageWithData:ideas] broadcast]</div><div><br>On 6 May 2016, at 07:57, Thorsten Seitz 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>+1<br></div><div><br data-mce-bogus="1"></div><div>I do like the syntax suggested by Dennis. Making use of Swift's ability to differentiate between external and internal parameter names is a great idea!<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>-Thorsten<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br>Am 06. Mai 2016 um 06:25 schrieb "T.J. Usiyan via swift-evolution" &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br><div><blockquote type="cite"><div class="msg-quote"><div dir="ltr">+1&nbsp;<div>I have wanted this since the first beta. I hadn't proposed because I haven't come up with a nice syntax to do this in functions/methods. I don't particularly like</div><div><div style="font-size: 13px;" data-mce-style="font-size: 13px;"><span style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;">&nbsp; &nbsp; func</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">&nbsp;takesATuple(someInt:&nbsp;</span><span style="font-family: 'menlo'; font-size: 11px; color: #703daa;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #703daa;">Int</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">, tuple (valueA, valueB): (<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>,&nbsp;<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>))</span></div></div><div><span style="font-family: Menlo;" data-mce-style="font-family: Menlo;" face="Menlo"><span style="font-size: 11px;" data-mce-style="font-size: 11px;"><br></span></span></div>and the closes that I have come is to simply reuse the closure syntax with<div><br></div><div><div style="font-size: 13px;" data-mce-style="font-size: 13px;"><span style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;">&nbsp; &nbsp; func</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">&nbsp;takesATuple(someInt:&nbsp;</span><span style="font-family: 'menlo'; font-size: 11px; color: #703daa;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #703daa;">Int</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">, tuple: (<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>,&nbsp;<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>)) {&nbsp;</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">&nbsp;(someInt,&nbsp;</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">(valueA, valueB)) in</span></div></div><div style="font-size: 13px;" data-mce-style="font-size: 13px;"><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;"><br></span></div><div><span style="font-family: Menlo;" data-mce-style="font-family: Menlo;" face="Menlo"><span style="font-size: 11px;" data-mce-style="font-size: 11px;">but that gets confusing in my opinion, specifically if you choose to&nbsp;have different names inside and outside.</span></span></div><div><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;"><br></span></div><div><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 5, 2016 at 11:22 AM, Dennis Weissmann via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" data-mce-href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex; border-left: 1px #ccc solid; padding-left: 1ex;" data-mce-style="margin: 0 0 0 0.8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;"><div>Following a short discussion with positive feedback on [swift-users](<a href="http://thread.gmane.org/gmane.comp.lang.swift.user/1812" data-mce-href="http://thread.gmane.org/gmane.comp.lang.swift.user/1812">http://thread.gmane.org/gmane.comp.lang.swift.user/1812</a>) I’d like to discuss the following:</div><div><br></div><div>Tuples should be destructible into their components in parameter lists.</div><div><br></div><div>Consider the following code:</div><div><br></div><div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span>&nbsp;a = [</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">1</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">2</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">3</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">4</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">5</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">6</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">7</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">8</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">9</span><span>]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span>&nbsp;b = [</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">1</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">2</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">3</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">4</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">5</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">6</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">7</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">8</span><span>,</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">9</span><span>]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo'; min-height: 13px;" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo'; min-height: 13px;"><span></span><br></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span>&nbsp;c =&nbsp;</span><span style="color: #3d1d81;" data-mce-style="color: #3d1d81;">zip</span><span>(</span><span style="color: #4f8187;" data-mce-style="color: #4f8187;">a</span><span>,</span><span style="color: #4f8187;" data-mce-style="color: #4f8187;">b</span><span>).</span><span style="color: #3d1d81;" data-mce-style="color: #3d1d81;">reduce</span><span>(</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>) { acc, tuple</span><span>&nbsp;</span><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>&nbsp; acc +&nbsp;tuple.</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>&nbsp;+&nbsp;tuple.</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>}</span></div><div><span><br></span></div></div></div><div><span style="font-family: Menlo;" data-mce-style="font-family: Menlo;" face="Menlo"><span style="font-size: 11px;" data-mce-style="font-size: 11px;">tuple</span></span>&nbsp;is of type&nbsp;<span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">(</span><span style="color: #703daa; font-family: 'menlo'; font-size: 11px;" data-mce-style="color: #703daa; font-family: 'menlo'; font-size: 11px;">Int</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">, </span><span style="color: #703daa; font-family: 'menlo'; font-size: 11px;" data-mce-style="color: #703daa; font-family: 'menlo'; font-size: 11px;">Int</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">).</span></div><div><br></div><div>The problem is that the calculation is not very comprehensible due to&nbsp;<span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">.</span><span style="font-family: 'menlo'; font-size: 11px; color: #272ad8;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #272ad8;">0&nbsp;</span>and&nbsp;<span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">.</span><span style="font-family: 'menlo'; font-size: 11px; color: #272ad8;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #272ad8;">1</span>. That’s when destructuring tuples directly in the parameter list comes into play:</div><div><br></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span>&nbsp;c =&nbsp;</span><span style="color: #3d1d81;" data-mce-style="color: #3d1d81;">zip</span><span>(</span><span style="color: #4f8187;" data-mce-style="color: #4f8187;">a</span><span>,</span><span style="color: #4f8187;" data-mce-style="color: #4f8187;">b</span><span>).</span><span style="color: #3d1d81;" data-mce-style="color: #3d1d81;">reduce</span><span>(</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>) { acc,&nbsp;</span><span>(valueA, valueB)<span>&nbsp;</span><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">in</span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>&nbsp; acc +&nbsp;</span><span>valueA&nbsp;+&nbsp;</span>valueB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>}</span></div></div><div><br></div><div>The above is what I propose should be accepted by the compiler (but currently isn’t).</div><div><br></div><div>Currently tuple destructuring is possible like this:</div><div><br></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span> c = zip(a,b).reduce(</span><span style="color: #272ad8;" data-mce-style="color: #272ad8;">0</span><span>) { (acc, tuple) </span><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>&nbsp; </span><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">let</span><span> (valueA, valueB) = tuple</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>&nbsp;&nbsp;</span><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">return</span>&nbsp;acc + valueA + valueB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span>}</span></div></div><div><br></div><div>This is not about saving one line ;-). I just find it much more intuitive to destructure the tuple in the parameter list itself.</div><div><br></div><div>The same thing could be done for functions:</div><div><br></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';" data-mce-style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'menlo';"><span style="color: #bb2ca2;" data-mce-style="color: #bb2ca2;">func</span><span> takesATuple(someInt: </span><span style="color: #703daa;" data-mce-style="color: #703daa;">Int</span><span>, tuple: (</span><span style="color: #703daa;" data-mce-style="color: #703daa;">String</span><span>, </span><span style="color: #703daa;" data-mce-style="color: #703daa;">String</span><span>))</span></div></div><div><br></div><div>Here we also need to destructure the tuple inside the function, but the intuitive place (at least for me) to do this would be the parameter list.</div><div><br></div><div>In the following example I'm making use of Swift’s feature to name parameters different from their labels (for internal use inside the function, this is not visible to consumers of the API):</div><div><br></div><div><span style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #bb2ca2;">func</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">&nbsp;takesATuple(someInt:&nbsp;</span><span style="font-family: 'menlo'; font-size: 11px; color: #703daa;" data-mce-style="font-family: 'menlo'; font-size: 11px; color: #703daa;">Int</span><span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">, tuple (valueA, valueB): (<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>,&nbsp;<span style="color: #703daa;" data-mce-style="color: #703daa;">String</span>))</span></div><div><br></div><div>Here&nbsp;<span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">valueA</span>&nbsp;and&nbsp;<span style="font-family: 'menlo'; font-size: 11px;" data-mce-style="font-family: 'menlo'; font-size: 11px;">valueB</span>&nbsp;would be directly usable within the function. The tuple as a whole would not be available anymore.</div><div><br></div><div><br></div><div>Now it’s your turn!</div><div><br></div><div>1. What do you think?</div><div>2. Is this worth being discussed now (i.e. is it implementable in the Swift 3 timeframe) or should I delay it?</div><div><br></div><div>Cheers,</div><br><div><div style="color: #000000; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" data-mce-style="color: #000000; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;"><div>- Dennis</div></div></div></div><br>_______________________________________________<br> swift-evolution mailing list<br> <a href="mailto:swift-evolution@swift.org" data-mce-href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" data-mce-href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br> <br></blockquote></div><br></div><div class="_stretch"><span class="body-text-content">_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" data-mce-href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" data-mce-href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></div></blockquote></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></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>