<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 7:52 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote class="gmail_quote" 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; margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word; line-break: after-white-space;" class=""><div class="">etc.&nbsp; 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="">&nbsp; &nbsp;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></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="">Yes, these are very interesting options to explore, and you're right that if we want to go down this road, then we'd need to imbue regex literals with certain "smarts" as opposed to having lenient regex literal parsing that entirely defers validation to a concrete regex type conforming to ExpressibleByRegularExpressionLiteral.</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=""><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="">I don't think it's an all-or-nothing proposition, though, as to whether the literal or the conforming type performs the validation. Personally, I think one of the strengths of Swift's literals is that they are intrinsically untyped and that multiple concrete types are expressible by them. </div></div></blockquote><div><br class=""></div><div>Right, but the string literal syntaxes we have (single and multiline) do not allow different grammars (e.g. escape sequences) depending on what type they are inferred to. &nbsp;Wouldn’t it be odd if a string literal accepted “\x12\u1212\U00001212” when it converts to a "const char *” but accepted “\u{12345}” when passed to a bridged Dart API?</div><div><br class=""></div></div><div class="">-Chris</div><div class=""><br class=""></div></body></html>