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.
[ Parent
| on HN ]
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.