<div dir="ltr"><div>If Swift is ever going to have multi-line string literals, type affixes should be a prefix and not a suffix. Otherwise the suffix would get lost at the end of a long string.</div><div><br></div><div><div>A nice extra use for affixes is as metadata so that your editor can do syntax highlighting. When I write r&quot;...&quot; in Python (for a raw string), my editor assumes that it is a regex and gives regex-specific highlighting. For SQL, it can only take a guess from the content.</div><div><br></div><div>So I can see re&quot;[a-z0-9]+&quot; and sql&quot;select * from table&quot; adding value, even if the latter is just a pass-through.</div><div><br></div><div>As far as raw strings go, the general feeling in the multi-line strings thread was to either go for single quotes or backticks. If backticks, it could married with this proposal as follows: any prefix + backticks = raw string. e.g.</div><div><br></div><div>r`raw string &quot;quotes&quot;`    // raw string</div><div>re`&lt;a href=&quot;[^&quot;]+&quot;&gt;`       // raw regex literal</div><div><span class=""><br></span></div>







<div><div>- Alex</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 12, 2015 at 9:19 PM, Kevin Ballard via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>




<div><div>I think you&#39;re reading too much into that one example. That was a demonstration of where the ambiguity between Character and UnicodeScalar matters, not the sole reason to use this. Suffice to say, I&#39;ve hit the ambiguity error between Characters and UnicodeScalars often enough to consider it worth addressing.<br></div>
<div> </div>
<div>-Kevin</div><div><div class="h5">
<div> </div>
<div>On Sat, Dec 12, 2015, at 03:26 AM, ilya via swift-evolution wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>&gt; var s = &quot;&quot;<br></div>
<div>&gt; s.append(&quot;c&quot;)<br></div>
<div>&gt;<br></div>
<div>&gt; This code looks pretty straightforward,<br></div>
<div> </div>
<div>This looks to me like you&#39;re adding a string, which can be done via <br></div>
<div> </div>
<div>s += &quot;c&quot;<br></div>
<div> </div>
<div>Yes, I know adding a character can theoretically be a bit more performant, but why would that be a consideration for static strings? Compiler should optimize both expressions above to the same result.<br></div>
<div> </div>
<div>&gt; UInt : u // or uint<br></div>
<div>&gt; Int16 : i16<br></div>
<div>&gt; Int32 : i32<br></div>
<div> </div>
<div>I think <br></div>
<div> </div>
<div>let number = 56i32<br></div>
<div> </div>
<div>is much less readable than <br></div>
<div> </div>
<div>let number: Int32 = 56<br></div>
<div> </div>
<div>so probably best not to encourage it.<br></div>
<div> </div>
</div>
<div><div> </div>
<div><div>On Sat, Dec 12, 2015 at 1:48 AM, Marc Knaup via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Too bad that string literals don&#39;t conform to a specific protocol.<br></div>
<div> </div>
<div>This would also be a nice but doesn&#39;t work:<br></div>
<div><p><span style="font-family:monospace,&#39; monospace&#39;"><span>// </span></span><span style="font-family:monospace,monospace">StaticString:</span><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">&quot;An simple string designed to represent text that is &#39;knowable at compile-time&#39;.&quot;<br></span><span style="font-family:monospace,monospace">extension</span><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">StaticString</span><span style="font-family:monospace,monospace"> {</span></p><p><span style="font-family:monospace,&#39; monospace&#39;"><span>    var</span><span> x: </span><span>Int</span><span> {<br></span><span>        return</span><span></span><span>123<br></span>    }<br>}<br><span><br>print</span><span>(</span><span>&quot;abc&quot;</span><span>.x)</span></span></p></div>
</div>
<div><div><div><div> </div>
<div><div>On Fri, Dec 11, 2015 at 11:38 PM, Joe Groff via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>I was a little disappointed something like this didn&#39;t already work:<br></div>
<div> </div>
<div>
struct Foo: StringLiteralConvertible { var f: Foo { return self } }<br></div>
<div>
struct Bar: StringLiteralConvertible { var b: Bar { return self } }<br></div>
<div> </div>
<div>
&quot;x&quot;.f // currently a failed lookup in String; could produce a Foo<br></div>
<div>
&quot;y&quot;.b // same, for Bar<br></div>
<div> </div>
<div>
-Joe<br></div>
<div> <span><br>
&gt; On Dec 10, 2015, at 11:07 AM, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br></span></div>
<div><div><div>&gt; The fact that Swift uses the exact same syntax (&quot;a&quot;) for String, Character, and UnicodeScalar can get annoying at times. When unconstrained it&#39;s always String, and the only way to disambiguate between the two when used in a context that takes both Character and UnicodeScalar is to explicitly constraint it further, e.g. with `&quot;a&quot; as Character`. A trivial example of this in action is<br></div>
<div>
&gt;<br></div>
<div>
&gt; var s = &quot;&quot;<br></div>
<div>
&gt; s.append(&quot;c&quot;)<br></div>
<div>
&gt;<br></div>
<div>
&gt; This code looks pretty straightforward, but it throws an ambiguity error (and the annoying part is, it doesn&#39;t actually matter which way it&#39;s resolved, the behavior is the same).<br></div>
<div>
&gt;<br></div>
<div>
&gt; Having to type `&quot;c&quot; as Character` and `&quot;c&quot; as UnicodeScalar` can get pretty annoying if you have to do it a lot. It would be great to reduce this typing a bit.<br></div>
<div>
&gt;<br></div>
<div>
&gt; My initial proposal here is to introduce string literal suffixes. Let me type something like `&quot;c&quot;c` for a Character and `&quot;c&quot;us` for a UnicodeScalar (and maybe `&quot;c&quot;s` to explicitly mean a String, although that&#39;s the default if unconstrained). AFAIK this is not ambiguous with the current syntax, as I don&#39;t believe it&#39;s ever legal to put an identifier like that after a string.<br></div>
<div>
&gt;<br></div>
<div>
&gt; Ideally this could be extended by library code with new suffixes. The obvious way to do that is to allow for a new type of &quot;operator&quot; declaration, perhaps something like `literal operator c { type Character }` (where `literal` is a context-sensitive keyword), which declares the suffix and the type (the actual type construction will be done with StringLiteralConvertible, StringInterpolationConvertible, UnicodeScalarLiteralConvertible, or ExtendedGraphemeClusterLiteralConvertible). If the same suffix is declared in two different modules that are imported into the same program, they&#39;re unambiguous within their source modules, and within the parent module using the suffix operator will be ambiguous unless further constrained (e.g. similar to using a function that&#39;s overloaded on its return type).<br></div>
<div>
&gt;<br></div>
<div>
&gt; One possible library use for this would be something like `&quot;^\s*foo&quot;r ` for a regular expression (although regular expressions probably also want some sort of &quot;raw&quot; string literal syntax to deal with escapes, but that&#39;s orthogonal to this proposal).<br></div>
<div>
&gt;<br></div>
<div>
&gt; Syntax is up for debate. I picked postfix characters because I believe it&#39;s ambiguous and it has precedent, both in C&#39;s numeric literals, and in C++11&#39;s user-defined literals (although C++11 has a required underscore before the literal, I believe this is just to allow C++11 to define its own new suffixes without ambiguity). This syntax could also work for numeric literals, come to think of it, with the same declaration and using IntegerLiteralConvertible or FloatLiteralConvertible. Heck, it could work for array and dictionary literals too, though that&#39;s less likely to be useful.<br></div>
<div>
&gt;<br></div>
<div>
&gt; FWIW, Playground color and image literals have the form [#Color(colorLiteralRed: 1, blue: 0, green: 0, alpha: 1)#] and [#Image(imageLiteral: &quot;hi.png&quot;)#]. These are interesting, but don&#39;t solve the original problem (of having to type out the full type name) so this syntax is not appropriate for this feature (but the syntax is fine for what Playgrounds use it for, which is to embed literal colors/images into the source code).<br></div>
<div>
&gt;<br></div>
<div>
&gt; -Kevin Ballard<br></div>
<div>
&gt; _______________________________________________<br></div>
<div>
&gt; swift-evolution mailing list<br></div>
<div>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div> </div>
<div>
_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
<div><img style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/fafb845a419772e6350c9cfbc9467eb4fbca434666071d51c515dc0560f54f7c/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3130793a4562723f463a6655493b47567f6d22324939655165497e48337c607439496a79796c4773766075343f4a40714c49616072366d22364e48446d2236426572536d223649634a5c4c4a4a7849743869694246603c48703172454758497473457658417b6d2236497d68325458393d2232427a717b423562623832564577613262797d2236417a587050536174333476735d4862594272407f4476635d2236484941476b467a5c4a53303376316551397659735e4d4236413d655d2236435167603a4d22324c623749303e435351763d22324a7768376465793478363153514264645242573c696352773559617565623a7d483354686035575b6c4532417d4d23344/open"> <br></div>
<div>_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div> </div>
</blockquote></div>
</div>
<div><img style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/ef4798b73b474ffd30ef5dcf38e7bed1d6145ee43227c0327356db6aa70b70cb/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e485d22324848367d2236483666713f6e6568686172303a723173653b4d223240775668575f643365787055723c415f456f4c4a5564415a677333656971717f6d42316f4d2236464560523e65407f4677623965647a4a63433264767377667541713d22364f6253636331445153375567427753657c494e4855476933776939577f4a7a763f4179487258546d6b46566139405a52756e4f6e437a5838336968437b436b62487577623b44767d4d675e4077723a584c6c607d223648446c424a76576a683e455c68596f653533377d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ufQ1sKmNNtjEC-2BBUON-2BgZPd8t-2F4PFTin0qlI9lRM0Al-2Fo0RNLyXGvN-2BQGfGaSDMNlf5Row4Hg8xxIMMDrkfL6WuTyPvAFBTUJwFGGqBelfe0IvGdRAXyPYMDhQ3WvhjYg6V2dj1kv038jAj7wizZIkPWkzrDEqzZBoY8LuIaqNd1eBRg1uxkOps7I1V-2F6fCzNM20n5F9Xpe-2BA6WFbDOAtbOyU-2F0AnknqITGHvxdsIPQ-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></div></div>


<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>