DIP1027 - Easy String Interpolation implementation

duckchess duckchess at chess.com
Tue Oct 24 16:17:06 UTC 2023


On Tuesday, 24 October 2023 at 11:32:19 UTC, deadalnix wrote:
> On Sunday, 22 October 2023 at 19:51:17 UTC, Imperatorn wrote:
>> On Sunday, 22 October 2023 at 19:35:46 UTC, deadalnix wrote:
>>> On Sunday, 22 October 2023 at 08:56:06 UTC, Walter Bright 
>>> wrote:
>>>> Several people asked for an implementation to try out, so 
>>>> here it is:
>>>>
>>>> https://github.com/dlang/dmd/pull/15722
>>>
>>> s/i/format!
>>
>> You forgot /g 😎
>
> I forgot to mention that baking a feature that works just fine 
> as a library in the language is a terrible idea.

Exactly. But the language currently lacks the tools to do it in a 
nice way. we'd need something like this:

```d
template FOO(T) {
     alias FOO = T;
}
pragma(msg, FOO!int); // FOO decays into int

template BAR(alias T) {
     enum BAR = T;
}
pragma(msg, BAR!42); // BAR decays into 42

// proposed new feature: automatic string mixins
template BAZ(string T) {
     mixin BAZ = T;
}
pragma(sg, BAZ!"42, 42"); // BAZ should decays into pragma(msg, 
mixin("42, 42"));
// note: mixin("42, 42") curently doesn't work either. but it 
sould be made to work so it becomes:
// pragma(msg, 42, 42);

```

would this be possible to implement in the compiler?



More information about the Digitalmars-d mailing list