DIP 1027---String Interpolation---Community Review Round 1

Meta jared771 at gmail.com
Wed Dec 11 20:46:03 UTC 2019

On Wednesday, 11 December 2019 at 20:28:21 UTC, Ola Fosheim 
Grøstad wrote:
> On Wednesday, 11 December 2019 at 19:15:18 UTC, Meta wrote:
>> The main sticking point is that you have to write 
>> mixin(interp!"....") so the symbols will be looked up in the 
>> proper scope. Unfortunately, that also means that the above 
>> syntax is the best a library solution can do, currently.
> Maybe "mixin" could be a return type requiring CTFE and 
> re-evaluated in the calling context?  A bit dangerous perhaps.

Yeah, I think if it comes down to adding a new language feature 
to the compiler, or changing how mixins behave in such a way that 
may be cause for security concerns, it's less costly to add the 
language feature.

Really, though, all that's needed is to allow mixin templates to 
be mixed in without using the `mixin` keyword (I say "all", but 
that's quite a large language change):

string interp(string s)()

mixin template i(string s)
     enum i = mixin(interp!s);

auto n = 2, m = 5;
auto s = i!"The product of ${n} and ${m} is ${n * m}";

More information about the Digitalmars-d mailing list