[swift-evolution] [Review] SE-0168: Multi-Line String Literals

Xiaodi Wu xiaodi.wu at gmail.com
Thu Apr 13 20:08:35 CDT 2017


On Thu, Apr 13, 2017 at 7:55 PM, Brent Royal-Gordon <brent at architechies.com>
wrote:

> On Apr 13, 2017, at 4:48 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> You say "this is the example set by `print`", but I don't think anything
>> else actually *follows* that example. No other I/O operation in Swift
>> behaves this way.
>>
>
> To be more accurate, it's not `print` that specifies this behavior, but
> rather the standard output stream's implementation of
> `TextOutputStream.write(_:)`. Swift *explicitly* leaves this choice up to
> the TextOutputStream-conforming type. That is, the behavior is up to the
> receiver and not the argument of a call to `TextOutputStream.write(_:)`.
>
>
> I feel like I must be misunderstanding what you're trying to say here,
> because I *think* what you're trying to say is that
> `TextOutputStream.write(_:)` is what decides whether to add the terminator,
> which is not only totally wrong (see https://github.com/apple/swift/blob/
> adc54c8a4d13fbebfeb68244bac401ef2528d6d0/stdlib/public/core/
> Print.swift#L260) but doesn't even make any sense since there's a
> terminator parameter on `print` but none on `write(_:)`.
>

Hmm, you're right here with respect to `print()`. It is, however,
explicitly contemplated in the documentation for
`TextOutputStream.write(_:)` that conforming types can also determine
whether or not to append a terminator, and which, inside their
implementation of `write`. The example given in the documentation is:

```
struct ASCIILogger: TextOutputStream {
    mutating func write(_ string: String) {
        let ascii = string.unicodeScalars.lazy.map { scalar in
            scalar == "\n"
              ? "\n"
              : scalar.escaped(asASCII: true)
        }
        print(ascii.joined(separator: ""), terminator: "")
    }
}
```



> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170413/ca0bb079/attachment.html>


More information about the swift-evolution mailing list