What do you thing about this string interpolation idea

12345swordy alexanderheistermann at gmail.com
Mon Dec 10 19:52:37 UTC 2018


On Monday, 10 December 2018 at 10:11:44 UTC, Daniel Kozak wrote:
> https://run.dlang.io/is/FbOnGI
>
> import std.stdio;
> template somefun()
> {
>      auto iterpolate(string s)()
>      {
>          //do some parsing
>          return mixin(s[1 .. $]);
>      }
> }
>
> enum enableInterpolate = "mixin somefun A; alias interpolate = 
> A.iterpolate;";
>
> void main()
> {
>     mixin(enableInterpolate);
>     int a = 5;
>     iterpolate!("$a").writeln;
> }

The issue that I have with this is that users do not want to 
manually add the mixin to the code scope every time they want 
string interpolation and worry about bugs that they may run 
across due to the misuse of the mixin. Let the compiler do the 
heavy lifting.


More information about the Digitalmars-d mailing list