[swift-evolution] multi-line string literals.

Cole Campbell cole.m.campbell at icloud.com
Fri Apr 29 11:08:31 CDT 2016


> On Apr 29, 2016, at 9:20 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>>> On Apr 28, 2016, at 4:52 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Did you ever really use multiline string literals before?
>> 
>> Yes. I used Perl in the CGI script era. Believe me, I have used every quoting syntax it supports extensively, including `'` strings, `"` strings, `q` strings, `qq` strings, and heredocs. This proposal is educated by knowledge of their foibles.
>> 
>> As outlined in the "Future directions for string literals in general" section, I believe alternate delimiters (so you can embed quotes) are a separate feature and should be handled in a separate proposal. Once both features are available, they can be combined. For instance, using the `_"foo"_` syntax I sketch there for alternate delimiters, you could say:
>> 
>>    let xml = _"<?xml version="1.0"?>
>>                "<catalog>
>>                " <book id="bk101" empty="">
>>                "     <author>\(author)</author>
>>                " </book>
>>                "</catalog>"_
> 
> Other than the underscores (I'm not sold on them but I could live with them), this is my favorite approach:
> 
> * It supports indented left-hand alignment, which is an important to me for readability
> * It avoids painful `\n"+` RHS constructions
> * It's easy to scan and understand
> * It's simple and harmonious
> 
This would ultimately be my favorite approach. I do like the underscores, because they're unobtrusive and don't distract the eye, but I'm interested to see alternative suggestions. However, I understand this is not considered in scope for the current proposal. Is the intention to propose alternate delimiters for Swift 3 now or wait?


More information about the swift-evolution mailing list