<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 19, 2015, at 5:29 PM, Al Skipp <<a href="mailto:al_skipp@fastmail.fm" class="">al_skipp@fastmail.fm</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On 19 Dec 2015, at 22:03, Radosław Pietruszewski via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="display: inline !important;">That is a fair position. It sounds like you oppose this shorthand for methods that require arguments but not for nullary methods and not for property getters. Is that correct? Do you believe it is valuable in those cases?</span></blockquote><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div><div class="">Correct. I’m for foo(.aMethod) and foo(.aProperty), but not foo(.aMethod(withArgs)), because the former maps pretty nicely to what we already have, and the latter can be seriously confusing.</div><div class=""><br class=""></div><div class="">PS. I’d like to try and analyze my Swift codebases to see how I usually use closures with things like map, just to have some (admittedly biased) data on what kind of patterns are common in practice.</div><br class=""><div class=""><div class="">— Radek</div></div></div></div></blockquote></div><div class=""><br class=""></div><div class="">Methods that take arguments do introduce some interesting problems. Here is an example with current Swift syntax:</div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"dog"</span><span style="" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"cat"</span><span style="" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"rat"</span><span style="" class="">].</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span><span style="" class=""> { $0.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">hasPrefix</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"ca"</span><span style="" class="">) } </span>// [false, true, false]</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Now if we wanted to use the following syntax instead:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><div style="margin: 0px; color: rgb(0, 132, 0);" class=""><span style="" class="">[</span><span style="color: rgb(209, 47, 27);" class="">"dog"</span><span style="" class="">,</span><span style="color: rgb(209, 47, 27);" class="">"cat"</span><span style="" class="">,</span><span style="color: rgb(209, 47, 27);" class="">"rat"</span><span style="" class="">].</span><span style="color: rgb(61, 29, 129);" class="">map</span><span style="" class="">(</span><span style="" class="">.</span><span style="color: rgb(61, 29, 129);" class="">hasPrefix</span><span style="" class="">(</span><span style="color: rgb(209, 47, 27);" class="">"ca"</span><span style="" class="">)</span><span style="" class="">)</span></div><div class=""><br class=""></div></div><div style="margin: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">This would require auto-currying of the function, so that the parameter passed to </span>‘<font color="#3d1d81" face="Menlo" class=""><span style="font-size: 11px;" class="">hasPrefix’ </span></font>is partially applied. The ‘map’ function would then pass each element of the Array to the partially applied function. Further more the order of the parameters would need to be reversed to get the expected result. Basically it would need to do something like the following:</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> hasPrefix(prefix: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span>)(str: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> str.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">hasPrefix</span>(prefix)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"dog"</span><span style="" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"cat"</span><span style="" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"rat"</span><span style="" class="">].</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">hasPrefix</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"ca"</span><span style="" class="">)) </span>// [false, true, false]</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><br class=""></div><div style="margin: 0px;" class="">Perhaps that’s too much implicit rearranging? I would find it odd if were necessary to use the current syntax for methods with arguments, but have the ability to use the shorter syntax for methods without args.</div><div style="margin: 0px;" class=""><br class=""></div></div></div></blockquote><br class=""></div><div>The shorthand syntax could be implemented in different was. If it is just shorthand for a single expression closure then rearranging the call like that isn’t necessary. In reality, from a user point of view it doesn’t matter how it is implemented and it might be best to think of it as a single expression closure regardless of how the implementation is done.</div><br class=""></body></html>