String Interpolation
duckchess
duckchess at chess.com
Sat Oct 21 20:22:44 UTC 2023
On Saturday, 21 October 2023 at 18:25:22 UTC, Adam D Ruppe wrote:
> On Saturday, 21 October 2023 at 15:59:06 UTC, duckchess wrote:
>> can we just lower ```___""``` into ```mixin(___!"")```, where
>> ```___``` can be any template name. this way you can implement
>> whatever interpolation method you want in a library.
>
> https://github.com/adamdruppe/interpolation-examples/blob/master/01-basics.d
>
> I'll add more examples to that repo as I have time, but this
> implementation allows libraries to do whatever methods they
> want.
I understand your proposal, and YADIP is better than DIP1037
imho. but it's adding a special case to the compiler and makes
```string result = i"$name! See that DIP $dipNumber is easy to
convert to string.".text;``` marginally better to write than what
we can do today to have the exact same outcome ```string result =
mixin(i!"$name! See that DIP $dipNumber is easy to convert to
string.");``` where ```i``` would be a mixin template capturing
the surrounding variables and returning an interpolated string.
if we just lower ```___""``` into ```mixin(___!"")```, we can
write
```
import std.sinterp : i;
string s = i"$name! See that DIP $dipNumber is easy to convert to
string.";
```
or
```
import std.sqlinterp : sql;
sqlstring s = sql"$name! See that DIP $dipNumber is easy to
convert to string.";
```
and if there's no matching template, then we get a normal "i not
found, did you forget to include std.sinterp?" error message.
there would be no need for the compiler to even know what string
interpolation is. we'd have 'mixin strings'™.
More information about the Digitalmars-d
mailing list