[swift-evolution] [Pitch] Improve String Literals

David Hart david at hartbit.com
Tue May 16 15:25:53 CDT 2017


The problem I see is that + is an operator of the Standard Library and not part of the core language. I wouldn’t want + to sometimes to be a runtime operation and other times a compile-time operation. No, I really think we need strong language support here.

> On 16 May 2017, at 22:20, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I agree with Ben—this is something that should just work for all string literals, and those protocols shouldn't be reasons to introduce a different syntax. It would be even more confusing for users to have to understand under which contexts they could use either `+` or juxtaposition and under which contexts they could *only* use juxtaposition.
> 
> 
> On Tue, May 16, 2017 at 12:28 PM Ben Rimmington via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> > On 16 May 2017, at 16:36, Gwendal Roué wrote:
> >
> >> Le 16 mai 2017 à 16:58, Tony Allevato <tony.allevato at gmail.com <mailto:tony.allevato at gmail.com>> a écrit :
> >>
> >> Regarding the C/Objective-C syntax, what would be the advantages over concatenating the strings with `+`?
> >
> > The support for ExpressibleByStringLiteral and ExpressibleByStringInterpolation protocols.
> 
> Would it be possible to have compile-time concatenation of *all* string literals using the `+` operator?
> 
>         // Written as:
>         @available(*, unavailable, message: "Long strings can be bro" +
>                                             "ken into two or more pieces.")
>         // Compiled as:
>         @available(*, unavailable, message: "Long strings can be broken into two or more pieces.")
> 
> This could also be used with types such as StaticString, which don't have their own `+` operator.
> 
>         // Written as:
>         let s: StaticString = "Long strings can be bro" +
>                               "ken into two or more pieces."
>         // Compiled as:
>         let s: StaticString = "Long strings can be broken into two or more pieces."
> 
> -- Ben
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170516/314ce64a/attachment.html>


More information about the swift-evolution mailing list