<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Jan 11, 2017, at 01:29, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>On Jan 11, 2017, at 01:11, Freak Show &lt;<a href="mailto:freakshow42@mac.com">freakshow42@mac.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 7, 2017, at 23:37, Derrick Ho &lt;<a href="mailto:wh1pch81n@gmail.com" class="">wh1pch81n@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">I think pattern matching is the most compelling reason to keep tuples.<span class="Apple-converted-space">&nbsp;</span><span class="Apple-converted-space">&nbsp;</span></span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">If they were gone, how would we replace the following?</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">switch (a, b) {</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">case (value1, value2):</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">case (value3, value4):</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">}</span></div></blockquote></div><br class=""><div class="">I meant to mention this: &nbsp;Smalltalk - Objective C's mother language - has no switch statement (or 'if' or loops either). &nbsp;The language is incredibly malleable because it only does one thing - send messages to objects and all the language constructs are in the library. &nbsp;It would take very little time to add one. &nbsp;Off and on someone does it as an exercise but it never sticks.</div><div class=""><br class=""></div><div class="">Instead, you just use a dictionary of closures. &nbsp;An Objective C equivalent might be:</div><div class=""><br class=""></div><div class="">NSDictionary* switch = @{</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>@[@0,@1]: ^{ NSLog(@"zero one"); },<span class="Apple-tab-span" style="white-space: pre;">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@[@1,@1]: ^{ NSLog(@"one one"); }</div><div class="">};</div><div class=""><br class=""></div><div class="">NSArray* pair = @[@3, @5];</div><div class=""><br class=""></div><div class="">(switch at:pair ifAbsent:^{})(); &nbsp;//where at:ifAbsent: is added in the Smalltalk style as an extension.</div><div class=""><br class=""></div><div class="">The Smalltalk equivalent (much less ugly because of the lack of @'s) is</div><div class=""><br class=""></div><div class="">&nbsp;switch := {</div><div class="">&nbsp; #(0 1) &nbsp; -&gt; [ Transcript nextPutAll: 'zero one' ] .</div><div class="">&nbsp; #(1 1) &nbsp; -&gt;&nbsp;[ Transcript nextPutAll: 'one one' ] .&nbsp;</div><div class="">&nbsp; #(1 2) -&gt; [ Transcript nextPutAll: 'one two' ] .</div><div class="">} asDictionary.</div><div class=""><br class=""></div><div class="">(switch at: pair ifAbsent:[ [] ]) value.</div><div class=""><br class=""></div><div class="">So its not like this is some kind of key feature. &nbsp;Switch's vs dictionaries of closures - pretty much the same thing as pattern matching goes. &nbsp;The only thing you have to do is put an object at key that identifies itself as equal to the pattern you will throw at it.</div></div></blockquote><br><div>I suspect that's a fair bit slower than a switch &nbsp;statement. I'm not in front of my computer, so I can't prove it, though.</div></blockquote><br><div>Also, Swift's dictionary requires its keys to conform to `Hashable`, which would mean we'd have to create a formal struct *and* the "==" method for it would have to act as a pattern matched instead of checking equality. I suspect this could break a great many things that depend on "Equatable" meaning what it says.</div><div><br></div><div>- Dave Sweeris (again)</div></body></html>