DIP1027 - Easy String Interpolation implementation

Walter Bright newshound2 at digitalmars.com
Tue Oct 24 18:23:50 UTC 2023


On 10/24/2023 4:32 AM, deadalnix wrote:
> I forgot to mention that baking a feature that works just fine as a library in 
> the language is a terrible idea.

True, but can it work as a library feature? Consider:

```
void test {
     int x = 78;
     func("x = $x");
}
```

In order for this to work, `x` has to undergo semantic analysis in the context 
of `test`. But it will get evaluated in the context of `func`, which would be 
incorrect.

The way to evaluate it in the context of `test` is to have `func` return a 
string and then apply a mixin. (There may be another way, but I can't think of one.)

So, it would have to be written as:

```
     mixin(func("x = $x");
```

As a general rule, things that are used a lot can benefit from syntactic sugar, 
which is what DIP1027 provides.


More information about the Digitalmars-d mailing list