String reboot - (1a) incidental whitespace
John Rose
john.r.rose at oracle.com
Fri Apr 19 00:29:29 UTC 2019
On Apr 16, 2019, at 4:03 PM, Liam Miller-Cushon <cushon at google.com> wrote:
>
> One disadvantage is the handling of the trailing newline. Requiring the closing delimiter to be on its own line means there's always a trailing newline in source. If we want to allow expressing multi-line strings that don't have a trailing newline we could automatically trim one trailing newline character, but then it would be necessary to leave an extra blank line after multi-line strings in cases where a trailing newline is actually desired.
I'm not sure it would be nicer, but here's a move to ponder:
If the trailing newline is always stripped, allow an explicit
\n (or maybe any number of them?) before the close-quote
to opt out of the stripping.
String message = """
hello
world
\n""";
Actual:
hello\n
world\n
It seems to me, though, that stripping the last \n by
default tends to create more surprising use cases.
Retaining a final \n is usually less surprising, AFAICS.
This puts the burden back on the uncommon stripping
case. We might want a way to say "delete that last newline,
even though I used it to make my pretty box". One way
to do this would be a new escape sequence for ML strings
only:
String message = """
hello
world\
""";
Actual:
hello\n
world
But if we don't care so much about brace-style layout,
this works just as well, without a new escape sequence:
String message = """
hello
world""";
Actual:
hello\n
world
More information about the amber-spec-observers
mailing list