Raw string literals -- where we are, how we got here
brian.goetz at oracle.com
Wed Mar 28 20:24:16 UTC 2018
My apologies, I left out one additional known limitation: raw string
literals that start or end with tick. There are numerous workarounds,
none of which are beautiful, such as:
String s = `` `foo` ``.trim();
String s = TICK + `foo` + TICK;
> ## Anomalies and puzzlers
> While the proposed scheme is lexically very simple, it does have some
> at least one surprising consequence, as well as at least one restriction:
> - The empty string cannot be represented by a raw string literal
> (because two consecutive ticks will be interpreted as a double-tick
> delimiter, not a starting and ending delimiter);
> - String containing line delimiters other than \n cannot be
> represented directly by a raw string literal.
> The latter anomaly is true for any scheme that is free of embedding
> anomalies (escaping) and that normalizes newlines. If we chose to not
> normalize newlines, we'd arguably have a worse anomaly, which is that
> the carriage control of a raw string depends on the platform you
> compiled it on.
> The empty-string anomaly is scary at first, but, in my opinion, is
> much less of a concern than the initial surprise makes it appear.
> Once you learn it, you won't forget it -- and IDEs and compilers will
> provide feedback that help you learn it. It is also easily avoided:
> use traditional string literals unless you have a specific need for
> raw-ness. There already is a perfectly valid way to denote the empty
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the amber-spec-experts