The state of string interpolation

Neia Neutuladh neia at ikeran.org
Thu Dec 6 21:06:16 UTC 2018


On Thu, 06 Dec 2018 20:45:57 +0000, Meta wrote:
> On Thursday, 6 December 2018 at 20:00:02 UTC, H. S. Teoh wrote:
>> Essentially, what you want to be able to do is essentially for a
>> template to be able to reference symbols in the caller's scope, rather
>> than in the template's scope.
> 
> Am I missing something? D has this already in the form of mixin
> templates.

>From the spec:

"A TemplateMixin can occur in declaration lists of modules, classes, 
structs, unions, and as a statement."

Also, it still requires the `mixin` keyword at the place of instantiation. 

So you want to write:

    writeln(interp!"Hi, ${user.name}!");

But you currently have to write:

    mixin interp!"Hi, ${user.name}!";
    writeln(interpResult);


More information about the Digitalmars-d mailing list