String interpolation, after a healthy debate on discord
WebFreak001
d.forum at webfreak.org
Tue Dec 14 16:15:28 UTC 2021
On Tuesday, 14 December 2021 at 16:04:58 UTC, Daniel N wrote:
> On Tuesday, 14 December 2021 at 15:58:21 UTC, WebFreak001 wrote:
>>> ubyte[] data = hex"AABBCC"; // ok
>>
>> I was thinking about this as well - it would work but would
>> run at runtime. I'm not a fan of using it just for static data
>> and think `hexString!"..."` is better for that.
>
> Then why isn't
> text!i"..."
> ok? Why do we need multiple
> i"..."
> f"..."
> ?
```d
string name = readln();
auto greeting = text!i"hello $name!";
```
expands to
```d
string name = readln();
auto greeting = text!(__header!..., "hello ", name, "!");
```
that wouldn't work because name is a runtime variable and you are
trying to use it as a template parameter here.
You would need to do `text(i!"hello $name!")` or `i"hello
$name!".text` for the YAIDIP to work
or as this post suggested a new calling syntax that extends to
that: `text"hello $name!"`
More information about the Digitalmars-d
mailing list