Where are we with thoughts on string interpolation and mixins?
Zoadian
no at no.no
Tue Nov 20 12:47:34 UTC 2018
> You almost prove some of the same points I'm trying to make :p
>
> "replace("%T%", T.stringof).replace("%TC%", TC.stringof)"
>
> Are not needed as %T% and %TC% are not in that string.
>
> And probably all the places you call LIQUID_ASGRAM_DEFINE_API
> have extra arguments that negatively impact any kind of code
> reviews. And this would happen constantly. Code evolves, so
> people will change LIQUID_ASGRAM_DEFINE_API and review it, and
> debug it.
>
> But on a side note, I do think that in some cases a .format()
> would be a lot more readable than string interop, especially
> where you are reusing one variable a lot of times. Like in your
> example:
Well, it's a direct translation of a C header
(https://github.com/jgaeddert/liquid-dsp/blob/master/include/liquid.h). That's why I kept it that way.
```
#define LIQUID_ASGRAM_DEFINE_API(ASGRAM,T,TC,TI)
````
The point I was trying to make is: I think we can build something
like this (https://run.dlang.io/is/NjHUah):
```
import std.stdio;
import std.array;
import std.traits;
string sinterp(string code, alias P1)() {
string s = code;
s = s.replace("$"~__traits(identifier, P1), P1);
return s;
}
void main() {
enum txt = "auto test";
pragma(msg, sinterp!(`$txt = 3;`, txt));
mixin(sinterp!(`$txt = 3;`, txt));
}
```
More information about the Digitalmars-d
mailing list