<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div>Hmm, I can see that Wux already replied to this question but let me give another more or less obvious answer which I believe has come up in a shape or another already:</div><div><br></div><div>Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">No, I am suggesting that whatever design is used for escaped newlines, if at all possible it should be equally apt for "strings" and """strings""" such that it will not require indentation stripping.</div></div></div></div>
</div></blockquote><br class=""></div><div>Could you share an example of such a design?</div></div></blockquote><div><br></div><div>One way to achieve the criteria below for both singly and triply quoted strings would be to borrow the <i>repeated opening quote</i> syntax (from earlier discussions) for singly quoted strings:</div><div><br></div><div> <b>let s1 = "abc\</b></div><div> <b>"def\n\</b></div><div> <b>"ghi \</b></div><div> <b>"xyz"</b></div><div><b> </b><span style="background-color: rgba(255, 255, 255, 0);">assert(s1 == <b>"abcdef\nghi xyz"</b>)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> </span></div><div> <b>let s2 = "abc\</b></div><div><b> "def\n\</b></div><div> /* Leading white space, */ <b>"ghi \</b></div><div> // as well as comments</div><div> </div><div> // and empty lines in between are</div><div> // insignificant when it comes to singly</div><div> // quoted literals.</div><div> "<b>xyz"</b></div><div><b> </b><span style="background-color: rgba(255, 255, 255, 0);">assert(s2 == s1)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> </span></div><div> <b>let s3 = """</b></div><div><b> abc\</b></div><div><b> def</b></div><div><b> ghi \</b></div><div><b> xyz</b></div><div><b> """</b></div><div> <span style="background-color: rgba(255, 255, 255, 0);">assert(s3 == s1)</span></div><div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">The criteria:</span></div><div><br></div></div><blockquote type="cite"><div>* Permits non-significant hard-wrapping in a string literal.</div></blockquote><div><br></div><div>✅ The string continues from the position of the backslash, with no extra space or line break inserted.</div><br><blockquote type="cite"><div><div>* Works equally well with single and triple string literals.</div></div></blockquote><div><br></div><div>✅ <span style="background-color: rgba(255, 255, 255, 0);">In both cases, a trailing `\` has the same meaning. In singly quoted strings, the only way to insert a newline is by quoting (`\n`), as it always was.</span></div><br><blockquote type="cite"><div><div>* Preserves code indentation, but does not require single string literals to do indentation stripping.</div></div></blockquote><div><br></div><div>✅ The indentation is just more explicit with singly quoted string literals.</div><br><blockquote type="cite"><div><div>* Is not horribly inconvenient.</div></div></blockquote><br><div>🤷♂️ Depends who you ask, I guess, but I think not horrible. And, after all, the programmer is free to choose between two quoting styles with different trade offs.</div><div><br></div><div>* * *</div><div><br></div><div>One thing that remains to be defined is whether trailing space is allowed (and ignored) after the backslash or not (and thus an error). I initially thought it's best to make into a compiler error, just like the indenting white space of the triple quoted string literals.</div><div><br></div><div>OTOH, we could also allow inline comments after the backslash:</div><div><br></div><div> let whyNot = "this, \</div><div> "that, \ <b>// <- Oxford comma</b></div><div> "and stuff"</div><div> assert(whyNot == "this, that, and stuff")</div><div> </div><div> let list = """</div><div> - this,</div><div> - that,\n\<b>// comment using "Adrian's \n\"</b></div><div> - and stuff</div><div> """</div><div> assert(list == "- this,\n- that,\n- and stuff")</div><div><br></div><div>[Nit: If comments after the backslash were allowed, we'd need to <b>either</b> require a space after the backslash (e.g. `\ //`), <b>or else</b> accept <span style="background-color: rgba(255, 255, 255, 0);">as string continuation / comment start markers</span> both `\//` (until newline) and `\/*` (until `*/`), as seen in the latter example above.]</div><div><br></div><div>I find this design — with or without comments — would naturally allow the programmer to choose between precision (singly quoted) and convenience/legibility (triply quoted). And of course it would allow breaking long string literals to multiple lines in a consistent way, which, for triply quoted strings, is also lighter than just concatenating with `+`.</div><div><br></div><div>— Pyry</div><div><br></div><div><span style="background-color: rgba(255, 255, 255, 0);">PS. I also slightly regret that SE-0168 ended up stripping the trailing newline, because multiline strings seem to compose (concatenate) better with a trailing newline there by default. But I understand if the inconvenience of `print(str, terminator: "")` weighed more than the other option.</span></div></div></body></html>