<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=""><div><blockquote type="cite" class=""><div class="">On Apr 11, 2017, at 7:33 AM, Vladimir.S via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span 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; float: none; display: inline !important;" class="">1. "Tripled string literals support backslash escapes and interpolation as normal, except that you can also place a backslash immediately before a newline. This indicates that the newline is merely for code formatting and should not be present in the resulting string:"</span><br 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=""><span 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; float: none; display: inline !important;" class="">- I think this a confusion point which should not be in this proposal. Currently in "normal" strings we just can't have single backlash as it will generate "invalid escape sequence in literal" warning.</span><br 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=""><span 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; float: none; display: inline !important;" class="">Is this feature worth the added complexity? I'm not sure currently.</span><br 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=""></div></blockquote></div><div class=""><br class=""></div><div class="">I should probably explain this feature a little better, but basically, it's there for two reasons:</div><div class=""><br class=""></div><div class="">1. It lets you suppress the trailing newline that this feature would otherwise add.</div><div class=""><br class=""></div><div class="">2. It lets you use multi-line string literals for strings which don't inherently have newlines in them, but which are long, so you want to hard-wrap them.</div><div class=""><br class=""></div><div class="">Let me explain that second one in more detail. Suppose we decide to reimplement Swift in Swift, and your job is to port the table of diagnostic messages. Some of these messages are pretty long. For example, here's one:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>WARNING(is_expr_same_type,none,<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> "checking a value with optional type %0 against dynamic type %1 "<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> "succeeds whenever the value is non-'nil'; did you mean to use "<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> "'!= nil'?", (Type, Type))</div><div class=""><br class=""></div><div class="">You decide to model the diagnostics as an enum:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension Diagnostic {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>enum Message {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>case isExprSameType(from: AST.Type, to: AST.Type)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">And now you want to write the actual error message. But this is a pretty long string. The project's coding standards requires that lines not get too wide, but you don't want actual newlines to be in the resulting string.</div><div class=""><br class=""></div><div class="">We think you should be able to write your code like this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension Diagnostic.Message: CustomStringConvertible {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>var description: String {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>switch self {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>case .isExprSameType(let from, let to):</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                </span>return """</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                        </span>checking a value with optional type \(from) against dynamic type \(to) \</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                        </span>succeeds whenever the value is non-'nil'; did you mean to use '!= nil'?\</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                        </span>"""</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class=""></div><div class="">You are using the (hopefully familiar) multiline string syntax and its (hopefully familiar) indentation support; you're just backslashing the newlines to indicate you don't really want them.</div><div class=""><br class=""></div><div class="">Now, one alternative to support this use case is to make newlines non-significant by default—if you wanted a real newline, you'd need to backslash it (or perhaps use `\n`). But that's no good because (a) we think significant newlines are the more obvious semantic and will be more common, and (b) when you're using non-significant newlines, you really care about the whitespace before the newline anyway. In this example, there's a space before one of the two backslashes; the string would not render correctly without that space. The backslash at the end of the line makes that whitespace visible and protects it from overzealous tools (like Xcode with certain settings enabled) which like to trim trailing whitespace from lines.</div><div class=""><br class=""></div><div class="">So, I think escaped newlines are a small but important tool that makes this feature applicable to more use cases. And I don't think they'll confuse users.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></body></html>