Update on String Templates (JEP 459)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Mar 14 19:24:37 UTC 2024


On 14/03/2024 19:04, Clement Cherlin wrote:

> What if instead of the extremes of a myriad of processors, or a single
> template prefix, or no prefix and complex/confusing context rules, we
> have exactly two prefixes? To avoid bikeshedding (obviously, the final
> names would be much shorter), I will call them TEMPLATE and
> INTERPOLATE. These are semantically identical to the old RAW and STR
> processors respectively, but syntactically have no "." between them
> and the leading quote.
>
> TEMPLATE"hey \{name}" -> StringTemplate
> INTERPOLATE"hey \{name}" -> String

See my latest email to Guy.

Having /different/ prefix for interpolated vs. raw template literals 
does help a bit with the case I brought up there - as here we’re 
basically in a world where a string literal with embedded arguments 
/must/ have a suitable prefix.

A possible point which is not too far from where we are today is just 
reuse STR and RAW as prefixes, but also make RAW /optional/, so that:

  * it can be used to disambiguate interpretation of strings w/o
    embedded expressions;
      o it can be the /default/ if you type something that does have
        embedded expressions (e.g. nudge towards the safer route if
        there’s embedded expressions)

Another idea that came up was, instead of just using prefixes, use /types/:

  * the STR prefix is written String
  * the RAW prefix is written StringTemplate

This is slightly better (say what you mean!) - but a potential problem 
is that one might wonder why a special syntax is needed given a cast is 
just a pair of |(| and |)| away…

Maurizio

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240314/a2eb5633/attachment-0001.htm>


More information about the amber-spec-observers mailing list