<html><head><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="">To audition Xcode using the following multi-line syntax:<div class=""><br class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;let xml = </span><span style="font-variant-ligatures: no-common-ligatures" class="">"&lt;?xml version=\"1.0\"?&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;catalog&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &lt;book id=\"bk101\" empty=\"\"&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;author&gt;\(author)</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&lt;/author&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;title&gt;XML Developer's Guide&lt;/title&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;genre&gt;Computer&lt;/genre&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;price&gt;44.95&lt;/price&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp; &nbsp; &lt;description&gt;An in-depth look at creating applications with XML.&lt;/description&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &lt;/book&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;/catalog&gt;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ""</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(xml)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div></div><div class="">You can install: &nbsp;<a href="http://johnholdsworth.com/swift-LOCAL-2016-04-25-a-osx.tar.gz" class="">http://johnholdsworth.com/swift-LOCAL-2016-04-25-a-osx.tar.gz</a></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 24 Apr 2016, at 23:35, Chris Lattner &lt;<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Apr 23, 2016, at 2:08 PM, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class="">I’m trying to avoid more advanced features such as the handling of indenting which<br class="">for me complicates something that if kept simple can be documented very easily.<br class=""></blockquote><br class="">I don't think you can tackle multiline strings without worrying about indenting. Indentation may fundamentally change the approach you choose.<br class=""></blockquote><br class="">I agree with this and almost every point you make in your email (and your other subsequent one about one approach maximally general). &nbsp;That said, I wonder if there is a different conclusion that can be reached. &nbsp;I’m going to rearrange your three features a bit:<br class=""><br class=""><blockquote type="cite" class="">The way I would prefer to tackle these is:<br class=""><br class="">* Multiline literals: If the closing quote of a string is not present, look at the next line. If it consists of (optional) indentation followed by a matching opening quote, the string has a newline and then continues after the quote on the next line. (The handling of comments is an open question here.)<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let xml: String = "&lt;?xml version=\"1.0\"?&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"&lt;catalog&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"\t&lt;book id=\"bk101\" empty=\"\"&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"\t\t&lt;author&gt;\(author)&lt;/author&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"\t&lt;/book&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"&lt;/catalog&gt;"<br class=""><br class="">The cool things about this are that (a) the compiler can tell you really do mean this to be part of the literal and you haven't just forgotten to close the string, and (b) there's no guesswork about how indentation should be handled. The uncool thing is that you need to insert the quote at the beginning of each line, so you can't just blindly paste into a multiline literal. Editors can help make that easier, though—a "paste as string literal" feature would be a nice addition to Xcode, and not just for multiline strings or just for Swift.<br class=""></blockquote><br class="">Yes, I completely agree. &nbsp;This is is awesome, and a nice &amp; simple generalization of our existing syntax. &nbsp;It has obvious behavior even if you encounter it in code without knowing about the feature.<br class=""><br class=""><blockquote type="cite" class="">* Disabling escapes: If you use single quotes instead of double quotes, backslash escapes are disabled.<br class=""></blockquote><br class="">We need a way to disable escapes, but it seems to me that (since it is orthogonal to the other concerns) that it should not be tied to the “multiple single quotes” syntax. &nbsp;What is your thought on “modifier” prefix characters for string literals? &nbsp;e.g.:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let x = e”no \escapes \(processed here”<br class=""><br class="">If we supported these, they would be supported with multi-line string literals by putting the modifiers on the first line of the literal, and the multi-line approach above would “just work”. &nbsp;You could introduce several different modifiers, e.g. one that disabled general escapes, but still allowed \(x) for substitution. &nbsp;<br class=""><br class=""><blockquote type="cite" class="">* Yes, with a number of backslashes matching the number of quotes, which allows you to insert literal \( text: '''<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;author&gt;\\\(author)&lt;/author&gt;<br class=""></blockquote><br class="">Egads!<br class=""><br class=""><blockquote type="cite" class="">Notes on alternatives:<br class=""><br class="">1. If you wanted to not provide no-escaping strings, an alternative would be to say that *all* escapes require as many backslashes as there are quotes in the string delimiter. Thus, a newline escape in a `"""` string would be `\\\n`. This would in practice give you the same flexibility to write a literal without worrying (much) about escaping.<br class=""></blockquote><br class="">I’m really not a fan of requiring “stacking” of escapes to re-enable them. &nbsp;This (IMO) just makes it less likely that you’ll run into an edge case. &nbsp;I also don’t like the “fix" being to have to use 5 quotes around your strings :-)<br class=""><br class=""><blockquote type="cite" class="">3. It might be useful to make multiline `"` strings trim trailing whitespace and comments like Perl's `/x` regex modifier does.<br class=""></blockquote><br class="">If you have modifier characters already, it is easy to build a small zoo full of these useful beasts.<br class=""><br class=""><blockquote type="cite" class="">* Alternative delimiters: If a string literal starts with three, or five, or seven, or etc. quotes, that is the delimiter, and fewer quotes than that in a row are simply literal quote marks. Four, six, etc. quotes is a quote mark abutting the end of the literal.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let xml: String = """&lt;?xml version="1.0"?&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""&lt;catalog&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t&lt;book id="bk101" empty=""&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t\t&lt;author&gt;\(author)&lt;/author&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t&lt;/book&gt;<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""&lt;/catalog&gt;"""<br class=""><br class="">You can't use this syntax to express an empty string, or a string consisting entirely of quote marks, but `""` handles empty strings adequately, and escaping can help with quote marks. (An alternative would be to remove the abutting rule and permit `""""""` to mean "empty string", but abutting quotes seem more useful than long-delimiter empty strings.)<br class=""></blockquote><br class="">I agree that there is a need to support alternative delimiters, but subjectively, I find this to be pretty ugly. &nbsp;It is also a really unfortunate degenerate case for “I just want a large blob of XML” because you’d end up using “"” almost all the time, and you have to use it on every line.<br class=""><br class="">For cases like this, I think it would be reasonable to have a “heredoc” like scheme, which does not allow leading indentation, and does work with all the same modifier characters above. &nbsp;I do not have a preference on a particular syntax, and haven’t given it any thought, but this would allow you to do things like:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let str = &lt;&lt;EOF<br class="">&lt;?xml version="1.0"?&gt;<br class="">&lt;catalog&gt;<br class="">\t&lt;book id="bk101" empty=""&gt;<br class="">\t\t&lt;author&gt;\(author)&lt;/author&gt;<br class="">\t&lt;/book&gt;<br class="">&lt;/catalog&gt;<br class="">EOF<br class=""><br class="">for example. &nbsp;You could then turn off escaping and other knobs using the modifier character (somehow, it would have to be incorporated into the syntax of course).<br class=""><br class="">I generally agree with your down thread remarks about how Swift doesn’t like to have multiple different solutions for the same problem. &nbsp;OTOH, you could look at “” syntax as being analogous to closure exprs, and heredoc syntax as being analogous to nested functions :-)<br class=""><br class="">-Chris<br class=""><br class=""><br class=""><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>