[swift-evolution] StringInterpolationConvertible and StringLiteralConvertible inheritance

Brent Royal-Gordon brent at architechies.com
Wed May 18 23:08:06 CDT 2016


> StringInterpolationConvertible inheritance of StringLiteralConvertible would
> allow "static-string" and \(string-expression) segments to be differentiated.
> 
> /// For example, `"<p>\(paragraph)</p>" as HTML` would invoke:
> ///
> /// HTML.init(stringInterpolation:
> ///     HTML.init(stringLiteral: "<p>"),
> ///     HTML.init(stringInterpolationSegment: paragraph),
> ///     HTML.init(stringLiteral: "</p>")
> /// )
> ///
> /// The conforming HTML type would be able to escape "<" and ">" characters
> /// in the \(paragraph) string, without affecting the "<p>" and "</p>" tags.
> ///
> protocol StringInterpolationConvertible : StringLiteralConvertible {
>    init(stringInterpolation: Self...)
>    init<T>(stringInterpolationSegment: T)
> }

I have some questions too about the relationship between StringInterpolationConvertible and StringLiteralConvertible, but I feel like I don't understand the rationale of the existing design well enough yet to suggest changes. So, can anybody involved in that provide some color?

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list