What do you thing about this string interpolation idea

Steven Schveighoffer schveiguy at gmail.com
Mon Dec 10 16:27:03 UTC 2018


On 12/10/18 11:11 AM, aliak wrote:
> This is much better than having to mixin everywhere. A couple of things:
> 
> 1) Can this be put in a module so that you don't have to 
> mixin(enableInterpolation) but instead "import interp = 
> std.interpolation;" or something similar?

No, you need a local mixin. Doing that import just imports the *symbol* 
into your namespace, but it doesn't give access to your namespace to the 
symbol.

> 2) This would unfortunately pollute the namespace and in code that uses 
> interpolation heavily, you'd have to rename it to something non-clashy 
> which I can see being quite annoying and a maintenance burden if it 
> turns out to be a common thing to do. Maybe if it's just standardly 
> called "interp" it may be alright though.

We can pass in the name we want to avoid conflicts.

So something like:

import std.interpolation;
mixin(enableInterpolate!"interp");

interp!("$a").writeln;

-Steve


More information about the Digitalmars-d mailing list