<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’d be fine with that.<div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 12.04.2017 um 12:59 schrieb Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">One last pitch, can we allow comments in multi-line strings if the string is broken up by a backslash?</p><pre style="margin: 15px 0px; 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(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" 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: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">
let myString = """
text text
text text text \ // Comment allowed in the current line here, but not in the line above it
text text text \ /* this type of comment is fine too */
text text\// notice whitespace can be ignored
"""
</code></pre><p style="margin: 15px 0px;" class="">You might have some interpolation and want to comment around it.</p><pre style="margin: 15px 0px; 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(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" 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: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">let foo = """
bar bar bar
bar \(x) bar\ // `x` does some magic
"""
</code></pre><div style="margin: 15px 0px;" class=""><br class="webkit-block-placeholder"></div></div><div class="bloop_original_html" style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><br class=""><div id="bloop_sign_1491994413280799744" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class=""><p class="airmail_on" style="margin: 15px 0px;">Am 12. April 2017 um 12:48:57, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">adrian.zubarev@devandartist.com</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="margin: 15px 0px;"><span style="margin-top: 0px; margin-bottom: 0px;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""></div><div class=""><div class="bloop_markdown"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">Actually I’m fine with such a compromise. Such a model has everything we’ve asked for, it’s easy, it has both leading and trailing precision and implicit new lines where needed.</p></div><div class="bloop_original_html"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><br class=""><div id="bloop_sign_1491994049751838976" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class=""><p class="airmail_on" style="margin: 15px 0px;">Am 12. April 2017 um 12:42:17, Vladimir.S via swift-evolution (<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="margin: 15px 0px;"><div style="margin-top: 0px; margin-bottom: 0px;" class=""><div class=""><span class="">On 12.04.2017 13:16, Thorsten Seitz via swift-evolution wrote:<br class="">>> Am 12.04.2017 um 10:11 schrieb Adrian Zubarev via swift-evolution<br class="">>> <<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">mailto:swift-evolution@swift.org</a>>>:<br class="">>><br class="">>> Great explanation thank you Brent. I’m convinced about the closing delimiter now. =)<br class="">>><br class="">>> -------------------------------------------------------------------------------------<br class="">>><br class="">>> If I understood correctly what Xiaodi Wu meant in his reply, then we could simplify<br class="">>> the whole multi-line string literal and also remove the need of disabling the<br class="">>> stripping algorithm.<br class="">>><br class="">>> We should ban these examples completely:<br class="">>><br class="">>> |"""Hello·world!"""|<br class="">>><br class="">><br class="">> Being able to use ""“ for single line strings containing lots of " is useful in<br class="">> itself and explained in the motivational section of the proposal:<br class="">> "Tripled string literals can also do double duty as a syntax for handling short<br class="">> string literals with many internal quotation marks“<br class="">><br class="">> -Thorsten<br class=""><br class="">Yes, I also think the single line string can be very useful and we should not<br class="">disallow it.<br class=""><br class="">But I agree that we should disallow multi-line cases when we have text on the same<br class="">line with leading or trailing """ because this complicates the mental modal and adds<br class="">confusion points.<br class=""><br class="">I.e. I suggest to allow only two forms:<br class="">1. Single line: """this is "just" text""" (no line end will be inserted)<br class="">2. Multiline, where leading and trailing """ has no text after/before them and *all*<br class="">the text is in lines *between* triple quotes:<br class="">"""<br class="">first line<br class="">second line<br class="">"""<br class=""><br class="">One can use backslash at the line end to emulate all other needed cases. Like:<br class=""><br class="">"""<br class="">first line \<br class="">second line\<br class="">"""<br class=""><br class="">will produce "first line second line"<br class=""><br class="">><br class="">>> |"""Hello↵ world!""" |<br class="">>> |"""Hello↵ world!↵ """ |<br class="">>> |"""↵ Hello↵ world!""" |<br class="">>><br class="">>> Instead an empty multi-line string literal would look like this:<br class="">>><br class="">>> |"""↵ """ |<br class="">>><br class="">>> To fix the above example you’d need to write it like this:<br class="">>><br class="">>> |"""↵ Hello·world!\↵ """ |<br class="">>> |"""↵ Hello↵ world!\↵ """ |<br class="">>><br class="">>> * Each line in between the delimiters would add implicit new lines if not<br class="">>> disabled by a backslash.<br class="">>> * The trailing precision is also handled by the backslash.<br class="">>> * The indent is handled by the closing delimiter.<br class="">>> * It’s easier to learn/teach.<br class="">>> * It’s easier to read, because most of the time the line where the starting<br class="">>> delimiter is, is filled with some other code.<br class="">>><br class="">>> |let myString = """↵ ⇥ ⇥ Hello↵ ⇥ ⇥ world!\↵ ⇥ ⇥ """ |<br class="">>><br class="">>> Now that would be a true multi-line string literal which needs at least two lines<br class="">>> of code. If you’d need a single line literal,|""|is the obvious pick.<br class="">>><br class="">>><br class="">>><br class="">>><br class="">>> --<br class="">>> Adrian Zubarev<br class="">>> Sent with Airmail<br class="">>><br class="">>> Am 12. April 2017 um 02:32:33, Brent Royal-Gordon (<a href="mailto:brent@architechies.com" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">brent@architechies.com</a><br class="">>> <<a href="mailto:brent@architechies.com" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">mailto:brent@architechies.com</a>>) schrieb:<br class="">>><br class="">>>><br class="">>>>> On Apr 11, 2017, at 8:08 AM, Adrian Zubarev via swift-evolution<br class="">>>>> <<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class="">>>>><br class="">>>>> That’s also the example that kept me thinking for a while.<br class="">>>>><br class="">>>>> -------------------------------------------------------------------------------------<br class="">>>>><br class="">>>>> Overall the proposal is a great compromise to some issues I had with the first<br class="">>>>> version. However I have a few more questions:<br class="">>>>><br class="">>>>> * Why can’t we make it consistent and let the compiler add a new line after the<br class="">>>>> starting delimiter.<br class="">>>>><br class="">>>>> |
let string = """↵ Swift↵ """ // result ↵Swift↵ |<br class="">>>>><br class="">>>>> If one would would the behavior from the proposal it’s really easy to add a<br class="">>>>> backslash after the starting delimiter.<br class="">>>>><br class="">>>>> |
let string = """\↵ Swift\↵ """ // result Swift |<br class="">>>>><br class="">>>>> This would be consistent and less confusing to learn.<br class="">>>>><br class="">>>> That would mean that code like this:<br class="">>>><br class="">>>> print("""<br class="">>>> A whole bunch of<br class="">>>> multiline text<br class="">>>> """)<br class="">>>> print("""<br class="">>>> A whole bunch more<br class="">>>> multiline text<br class="">>>> """)<br class="">>>><br class="">>>> Will print (with - to indicate blank lines):<br class="">>>><br class="">>>> -<br class="">>>> A whole bunch of<br class="">>>> multiline text<br class="">>>> -<br class="">>>> -<br class="">>>> A whole bunch more<br class="">>>> multiline text<br class="">>>> -<br class="">>>><br class="">>>> This is, to a first approximation, never what you actually want the computer to do.<br class="">>>>><br class="">>>>> * Can’t we make the indent algorithm work like this instead?<br class="">>>>><br class="">>>>> |let string = """\↵ ····<tag>↵ ······content text↵ ····</tag>""" // Indent starts<br class="">>>>> with the first non space character // result <tag>↵ ··content text↵ </tag> |<br class="">>>>><br class="">>>>> The line where the closing delimiter is trims all space chapters and the indent<br class="">>>>> for the whole multi-line string is starting at the point where the first<br class="">>>>> non-space chapters is in that line.<br class="">>>>><br class="">>>> We could; I discuss that briefly in the very last section, on alternatives to the<br class="">>>> indentation stripping we specify:<br class="">>>><br class="">>>> • Stripping indentation to match the depth of the least indented line: Instead of<br class="">>>> removing indentation to match the end delimiter, you remove indentation to match<br class="">>>> the least indented line of the string itself. The issue here is that, if all lines<br class="">>>> in a string should be indented, you can't use indentation stripping. Ruby 2.3 does<br class="">>>> this with its heredocs, and Python's dedent function also implements this behavior.<br class="">>>><br class="">>>> That doesn't quite capture the entire breadth of the problem with this algorithm,<br class="">>>> though. What you'd like to do is say, "all of these lines are indented four<br class="">>>> columns, so we should remove four columns of indentation from each line". But you<br class="">>>> don't have columns; you have tabs and spaces, and they're incomparable because the<br class="">>>> compiler can't know what tab stops you set. So we'd end up calculating a common<br class="">>>> prefix of whitespace for all lines and removing that. But that means, when someone<br class="">>>> mixes tabs and spaces accidentally, you end up stripping an amount of indentation<br class="">>>> that is unrelated to anything visible in your code. We could perhaps emit a<br class="">>>> warning in some suspicious circumstances (like "every line has whitespace just<br class="">>>> past the end of indentation, but some use tabs and others use spaces"), but if we<br class="">>>> do, we can't know which one is supposed to be correct. With the proposed design,<br class="">>>> we know what's correct—the last line—and any deviation from it can be flagged *at<br class="">>>> the particular line which doesn't match our expectation*.<br class="">>>><br class="">>>> Even without the tabs and spaces issue, consider the case where you accidentally<br class="">>>> don't indent a line far enough. With your algorithm, that's indistinguishable from<br class="">>>> wanting the other lines to be indented more than that one, so we generate a result<br class="">>>> you don't want and we don't (can't!) emit a warning to point out the mistake. With<br class="">>>> the proposed algorithm, we can notice there's an error and point to the line at fault.<br class="">>>><br class="">>>> Having the closing delimiter always be on its own line and using it to decide how<br class="">>>> much whitespace to strip is better because it gives the compiler a firm baseline<br class="">>>> to work from. That means it can tell you what's wrong and where, instead of doing<br class="">>>> the dumb computer thing and computing a result that's technically correct but useless.<br class="">>>>><br class="">>>>> PS: If we’d get this feature in Swift, it would be nice if Xcode and other IDEs<br class="">>>>> which supports Swift could show space characters that are inside a string literal<br class="">>>>> (not other space character <- which is already supported), so it would be easier<br class="">>>>> to tell what’s part of the string and what is not.<br class="">>>>><br class="">>>> That would be very nice indeed. The prototype's tokenizer simply concatenates<br class="">>>> together and computes the string literal's contents after whitespace stripping,<br class="">>>> but in principle, I think it could probably preserve enough information to tell<br class="">>>> SourceKit where the indentation ends and the literal content begins. (The<br class="">>>> prototype is John's department, though, not mine.) Xcode would then have to do<br class="">>>> something with that information, though, and swift-evolution can't make the Xcode<br class="">>>> team do so. But I'd love to see a faint reddish background behind tripled string<br class="">>>> literal content or a vertical line at the indentation boundary.<br class="">>>><br class="">>>> In the meantime, this design *does* provide an unambiguous indicator of how much<br class="">>>> whitespace will be trimmed: however much is to the left of the closing delimiter.<br class="">>>> You just have to imagine the line extending upwards from there. I think that's an<br class="">>>> important thing to have.<br class="">>>><br class="">>>> --<br class="">>>> Brent Royal-Gordon<br class="">>>> Architechies<br class="">>>><br class="">>><br class="">>> _______________________________________________<br class="">>> swift-evolution mailing list<br class="">>><span class="Apple-converted-space"> </span><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">mailto:swift-evolution@swift.org</a>><br class="">>><span class="Apple-converted-space"> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">><br class="">><br class="">><br class="">> _______________________________________________<br class="">> swift-evolution mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><br class="">><span class="Apple-converted-space"> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></div></blockquote></div><div class="bloop_markdown"></div></div></div></span></blockquote></div><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);"><div style="margin: 15px 0px; -webkit-margin-before: 0px;" class=""><br class="webkit-block-placeholder"></div></div><span style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);" class=""><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br style="font-family: Helvetica, Arial; font-size: 13px; 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; background-color: rgb(254, 254, 254);" class=""></div></blockquote></div><br class=""></div></body></html>