<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="">I’m not saying that the + operator should automatically add a newline. I’m saying that both strings should contain a trailing newline, such that the visible result is the same.<div class=""><br class=""></div><div class="">By contrast, this would feel really strange:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">let a = """<br class=""></span><span style="font-family: Menlo;" class="">This is line one<br class=""></span><span style="font-family: Menlo;" class="">This is line two</span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class=""><br class=""></span><span style="font-family: Menlo;" class="">"</span><font face="Menlo" class="">""</font></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class="">let b = """<br class=""></span><span style="font-family: Menlo;" class="">This is line three<br class=""></span><span style="font-family: Menlo;" class="">This is line four</span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">"</span><font face="Menlo" class="">""</font></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class="">(a + b) ==&nbsp;"""<br class=""></span><span style="font-family: Menlo;" class="">This is line one<br class=""></span><span style="font-family: Menlo;" class="">This is line two<br class=""></span><span style="font-family: Menlo;" class="">This is line three<br class=""></span><span style="font-family: Menlo;" class="">This is line four</span><div class=""><div class="gmail_quote"><div class="" style="word-wrap: break-word;"><div class=""><font face="Menlo" class="">"""</font></div></div></div></div></blockquote><div class=""><blockquote type="cite" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="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 class="" style="word-wrap: break-word;"><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"></blockquote></div></blockquote></div></blockquote><div class=""><br class=""></div><div class="">On initial intuition, it seems strange that ‘a’ has a blatantly visible blank line at the end which seemingly “disappears” when the strings are concatenated. If I think about it for a bit, I can understand why that would be the case, but I think it’s non-obvious.</div><div class=""><br class=""></div><div class="">-BJ</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 14, 2017, at 3:49 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="">I disagree. I expect the last result to be from `a + "\n" + b`, for the reasons I outlined earlier.<br class=""><br class="">The concatenation operator + does not introduce implied separators when joining strings. There is no reason to think that it should for multi-line strings specifically.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Apr 14, 2017 at 16:35 BJ Homer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div style="margin: 15px 0px; font-family: Helvetica, Arial; font-size: 13px;" class=""><br class="webkit-block-placeholder"></div><blockquote type="cite" class=""><p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px" class="">Consider these two examples:</p><pre style="margin-top:15px;margin-bottom:15px;font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal" class=""><code class="m_-3264081925624959069swift" style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">let string_1 = """foo"""


let string_2 = """
    foo
    """
</code></pre><p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px" class="">What’s the intuitive result you’d expect without taking all the long talk from the list into account?</p><p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px" class="">Personally, I’d say&nbsp;<code style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal" class="">string_1 == string_2</code>&nbsp;is true.</p></blockquote><div class=""><br class=""></div></div><div style="word-wrap:break-word" class=""><div class="">I think it’s reasonable to expect them to be different, actually. I might call these “single-line” and “multi-line” mode strings. The single-line mode is primarily useful for being able to include unescaped double-quotes in the string. If you’re in multi-line mode, though, it’s reasonable to be thinking about things in terms of “lines”, and having a trailing newline there seems reasonable. For example, I think it’s reasonable to expect this:</div><div class=""><font face="Menlo" class=""><br class=""></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><font face="Menlo" class=""><span class=""><div class="">let a = """</div></span></font><font face="Menlo" class=""><span class=""><div class="">This is line one</div></span></font><font face="Menlo" class=""><span class=""><div class="">This is line two"</div></span></font><font face="Menlo" class=""><span class=""><div class="">"""</div></span></font><font face="Menlo" class=""><span class=""><div class=""><br class=""></div></span></font><font face="Menlo" class=""><span class=""><div class="">let b = """</div></span></font><font face="Menlo" class=""><span class=""><div class="">This is line three</div></span></font><font face="Menlo" class=""><span class=""><div class="">This is line four</div></span></font><font face="Menlo" class=""><span class=""><div class="">"""</div></span></font><span class=""><br class=""></span><div class=""><font face="Menlo" class="">(a + b) ==&nbsp;"""</font></div><div class=""><font face="Menlo" class="">This is line one</font></div><div class=""><font face="Menlo" class="">This is line two</font></div><div class=""><font face="Menlo" class="">This is line three</font></div><div class=""><font face="Menlo" class="">This is line four</font></div><div class=""><font face="Menlo" class="">"""</font></div></blockquote><div class=""><br class=""></div><div class="">That seems like a reasonable model to work with multi-line strings.</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">-BJ</div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></body></html>