String Interpolation
Arafel
er.krali at gmail.com
Sun Oct 22 21:32:15 UTC 2023
On 22/10/23 22:44, Adam D Ruppe wrote:
> What's your evidence for this?
There's obviously no scientific evidence, because I don't think anybody
has researched the topic.
But as an example, and perhaps ironically, let me point you to none
other than yourself (or at least something co-authored by yourself).
From
[DIP1036](https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1036.md#description):
> The primary use case is to employ the literal in place of a
string-yielding expression:
>
> ```d
> void foo(string s);
>
> foo(i"Hello, my name is ${name} and I am ${age} years old.");
>
> string s = i"${var1} + ${var2} = ${var1 + var2}";
> ```
Other than this, I would say that the fact that most (all?) languages
that support string interpolation allow implicit conversion to string
(or whatever other way of seamless replacing a string with an
interpolated string) should be a really strong hint.
Is there even any counter-example, i.e. any language where an
interpolated string cannot be used anywhere a regular string would be used?
Now, don't misunderstand me. I get that there are good reasons why it
might not be desirable to have this behaviour in D. But then please just
don't use a misleading name and syntax that will run opposite to most
people's expectations, unless you want to keep explaining to new users that:
```d
string rs = r"This a string";
string qs = q"(This also is a string)";
//string is = i"This is an interpolated string, absolutely not a string";
```
And why you need to call `format` (DIP1027) / `text` (YAIDIP) in that case.
More information about the Digitalmars-d
mailing list