Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by layer8 on Friday March 03, 2023 @06:01PM
(#35016204)
They want
String info = "My name is \{name}";
to be a compile-time error because it is missing the template processor (e.g. the `STR.` prefix). Since existing code like String info = "My name is ${name}";
is valid, they can’t use that syntax, or any other syntax that is currently allowed, since otherwise they would lose the ability to make it an error.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by ec109685 on Friday March 03, 2023 @08:41PM
(#35017278)
Futzing around with quotes like that is worse to type and it’s nice having distinct characters for open and close.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by layer8 on Friday March 03, 2023 @08:48PM
(#35017318)
It makes perfect sense to have the expressions outside of the string literals, exactly because they are expressions and not literal. Quotes express literalness, the opposite of evaluation.
This is simply replacing the existing
"My name is " + name + "."
by "My name is " (name) "."
by eliminating the plusses, and adding parentheses to make expressions like "My name is " ("John") "."
unambiguous (a string template with one parameter that happens to be a string literal). The parentheses also indicate that this is a parameter (to the string template) that is immediately evaluated, like for a function call. (The whole string template feature is really just syntactic sugar for a function call.)That way you don’t have to “interrupt” string literals with an expression. Instead you end the string literal normally and then comes an expression.
A string template would be defined as any sequence of string literals and parenthesized expressions.
> For the syntax of embedded expressions we considered using ${...}, but that would require a tag on string templates (either a prefix or a delimiter other than ") to avoid conflicts with legacy code.
Can't the template processor expression itself function as the tag? Is STR."..." already legal now?