String Interpolation

duckchess duckchess at chess.com
Sun Oct 22 22:57:30 UTC 2023


On Sunday, 22 October 2023 at 21:55:23 UTC, Steven Schveighoffer 
wrote:
> On Sunday, 22 October 2023 at 21:32:15 UTC, Arafel wrote:
>> 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}";
>> > ```
>
> FWIW, that is something Adam opposed, but I insisted on. I did 
> not think a String Interpolation DIP would be viable without it.
>
> I still feel like one should be able to use an interpolation 
> tuple as a string, but it's really hard to come up with a 
> design that doesn't feel like a complete hack.
>
> It's indeed much much simpler to just push that requirement to 
> build a string if desired on the user.
>
> -Steve

or improve the language, so we can express what we want in a 
library.
something like this:
````
writeln(mixin("5, 7"));
```
and
````
mixin(string) nothing(string s)() { return s; }
writeln(nothing!"5, 7");
```

and i don't know if that would work either, but there should be 
_some_ way to make it possible to implement every form of 
interpolation exactly like YAIDIP or DIP1027 work completely in 
library code. bonus, this might be useful for other this too.


More information about the Digitalmars-d mailing list