[swift-evolution] multi-line string literals
Travis Tilley
ttilley at gmail.com
Mon Dec 14 20:24:29 CST 2015
Dear core team:
What syntax would *you* personally prefer for unescaped strings?
'''
>
> this doesn't do anything:
> \
> \n \t \a
>
> moo cow
> '''
and:
'\'
Or:
r"""
>
> this doesn't do anything:
> \
> \n \t \a
>
> moo cow
> """
and:
r"\"
...perhaps with a capital R. Maybe an RC or RS instead (for raw characters
or raw string).
The single quote version is more consistent with other languages with this
feature (ruby, perl, bourne, other shells). It would also be easier to
parse and allow you to define the resulting type after the variable rather
than inferring from the literal (which is how I prefer
StringLiteralConvertible to work, at least from current experience). You
can build some powerful code on top of StringLiteralConvertible and just
leaving the string literal *alone*.
The r/R/RC/RS prefix versions are consistent-ish sorta kinda-almost with
python, and might tie into the existing proposal for literal
prefixes/suffixes if that proposal is approved. The details of that would
have to be decided in the other thread, but I don't personally see that as
an obstacle for implementing the feature of enhanced multi-line and
unescaped strings first... even before other typing modifiers are decided
upon.
I prefer single quotes and triple single-quotes, as it feels more natural
and familiar for me *personally...* but either syntax would make me
significantly happier than not having one at all, and I haven't
internalized "the swift way" quite like the core team has.
-Travis Tilley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/b3730827/attachment.html>
More information about the swift-evolution
mailing list