<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><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="">Hello,<div class=""><br class=""></div><div class="">I would like to suggest an additive evolution to Swift that might be in scope of phase 1 of Swift 4 (because it might have an impact on the ABI).</div><div class=""><br class=""></div><div class="">The idea is to extend the pattern matching abilities of Swift to enable a recursive programming style that’s very common in languages such as Lisp, ML, or Prolog on a collection that is processed as a list. By analogy to ML, Swift could do that on tuples, or on arrays, or on any similar, perhaps new, data type. This would allow the following for example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> listOfDifferenceOfListElements (list: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">List</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> list {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘〙</span><span style="font-variant-ligatures: no-common-ligatures" class="">: {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘〙</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〙</span><span style="font-variant-ligatures: no-common-ligatures" class="">: {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〙</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a, let b </span><span style="line-height: normal; font-family: 'Apple Symbols'; font-variant-ligatures: no-common-ligatures;" class="">⫸</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> tail </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〙</span><span style="font-variant-ligatures: no-common-ligatures" class="">: {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〘</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a-b </span><span style="line-height: normal; font-family: 'Hiragino Sans'; font-variant-ligatures: no-common-ligatures;" class="">〙</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="line-height: normal; font-family: 'Apple Symbols'; font-variant-ligatures: no-common-ligatures;" class="">⋙</span><span style="font-variant-ligatures: no-common-ligatures" class=""> sumDifferenceOfListElements(tail)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><span style="font-family: 'Hiragino Sans'; font-size: 14px;" class="">Where I deliberately used unusual Unicode characters to denote syntax that would need to be invented:</span></div><div class=""><br class=""></div><div class="">- <font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">〘〙 to denote the list-like data structure. It would be old style parenthesis if we wanted that to be Swift’s tuple, or the usual bracket if it was arrays</span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">- </span></font><span style="font-family: 'Apple Symbols'; font-size: 14px;" class="">⫸</span><span style="font-size: 14px; font-family: 'Hiragino Sans';" class=""> to pattern-match the tail of the list, i.e. the list composed of any and all elements following whatever has been pattern-matched so far</span></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">- </span></font><span style="font-family: 'Apple Symbols'; font-size: 14px;" class="">⋙</span><span style="font-size: 14px; font-family: 'Hiragino Sans';" class=""> to denote a list append operator.</span></div><div class=""><span style="font-size: 14px; font-family: 'Hiragino Sans';" class=""><br class=""></span></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">If we wanted the list data-type to be tuples, this would require the ability to build longer tuples from existing ones, i.e. </span></font><span style="font-size: 14px; font-family: 'Hiragino Sans';" class="">build (a, b, c) from a and (b, c), or from (a) and (b, c) (appending tuples). Array seems more suitable, however.</span></div><div class=""><span style="font-size: 14px; font-family: 'Hiragino Sans';" class=""><br class=""></span></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">So this post is to assess the interest in such a feature. Also note that while I have tried to have an occasional look at this mailing list in the past, due to its overwhelming volume, I may very well have missed a similar discussion in the past. In that case, I would appreciate a pointer.</span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">As someone who developed Lisp and Prolog software professionally in a rather distant past, with an ever renewed sense of wonder, I would very much love to be able to use that programming style again when it makes sense.</span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">If there is interest, I would be willing to write up an evolution proposal.</span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Hiragino Sans" class=""><span style="font-size: 14px;" class="">Jean-Denis Muys</span></font></div><div class=""><br class=""></div></body></html>