opMixin or mixin function templates with convenience operator?

Paul Backus snarwin at gmail.com
Thu Dec 12 18:24:30 UTC 2019

On Thursday, 12 December 2019 at 17:26:19 UTC, jmh530 wrote:
> The idea for the convenience operator is discussed on the DIP 
> 1027 thread [1] by Paul Backus (though he uses @ and I'm a bit 
> more sympathetic to your #). The way he describes it is just a 
> simple re-write of
> writeln(@interp!"The number ${num} doubled is ${num * 2}!"));
> to
> writeln(mixin(interp!"The number ${num} doubled is ${num * 
> 2}!"));
> I find it an interesting idea, but wonder what the consequences 
> of this are more generally.

I managed to find the source for this idea: it's a Github comment 
by Nick Treleaven on an earlier string interpolation DIP.


Personally, I prefer this rewriting approach to something like 
opMixin because it doesn't require you to declare a struct as 
boilerplate, and it works "out of the box" for both templates and 
CTFE, as well as "naked" strings:

     #foo!(args) => mixin(foo!args)
     #foo(args)  => mixin(foo(args))
     #someCode   => mixin(someCode)

More information about the Digitalmars-d mailing list