<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 24, 2017, at 4:15 PM, Chris Lattner <<a href="mailto:clattner@nondot.org" class="">clattner@nondot.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class="Apple-interchange-newline">than the same type having a collection of named matches using the usual Perl syntax?</div><div class=""><br class=""></div><div class=""> if case /(?<firstName>[a-zA-Z]+) (?<lastName>[a-zA-Z]+)/ = getSomeString() {</div><div class=""> print(Regex.captured["firstName"], Regex.captured["lastName"])</div><div class=""> }</div></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Personally, I really don’t like this. It turns a structured problem into one that violates DRY and loses the structure inherent in the solution. Also, while theoretically the dictionary could be optimized away, in practice that would be difficult to do without heroics.</div><br class="Apple-interchange-newline"></div></blockquote></div><br class=""><div class="">One other minor and obscure point: if the compiler is aware of the regex grammar it can properly type the matches, I can imagine the following cases:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">if case /(let name: [a-zA-Z]+) (let count: Int)/ = getSomeString() {</div><div class=""> print(name, count)</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">-> name has type String, count has type Int (and matches [0-9]+)</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class="">if case /(let name: [a-zA-Z]+)? (let count: Int)/ = getSomeString() {</div><div class=""> print(name, count)</div><div class="">}</div><div class=""><br class=""></div></blockquote></div><div class="">-> name has type String?</div><div class=""><br class=""></div><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class="">if case /(let name: [a-zA-Z]+)* (let count: Int)/ = getSomeString() {</div><div class=""> print(name, count)</div><div class="">}</div><div class=""><br class=""></div></blockquote>-> name has type [String]</div><div class=""><br class=""></div><div class="">etc. Even if we don’t have a “default regex” for types, it would still be awesome to be able to write:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class="">if case /(let name: [a-zA-Z]+) (let count: Int: [0-9]+)/ = getSomeString() {</div><div class=""> print(name, count)</div><div class="">}</div><div class=""><br class=""></div></blockquote></div><div class="">and have that transparently invoke and check the Int?(string) failable initializer.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""></div></body></html>