What do you thing about this string interpolation idea

aliak something at something.com
Mon Dec 10 16:11:17 UTC 2018


On Monday, 10 December 2018 at 15:50:58 UTC, Steven Schveighoffer 
wrote:
> On 12/10/18 7:45 AM, FeepingCreature wrote:
>> On Monday, 10 December 2018 at 12:34:33 UTC, Daniel Kozak 
>> wrote:
>>> https://gist.github.com/run-dlang/a0dce06b873b216680df673661e4b4e6
>> 
>> While I'm not sure of all the details of the implementation, I 
>> think the use of a mixed in templated nested function to 
>> enable access to the local scope without string mixin is 
>> inspired. Very clever idea.
>
> Yeah, this looks a lot better than mixing in every 
> interpolation.
>
> I tried it out with adding arbitrary expressions, and it works 
> like a charm: 
> https://gist.github.com/run-dlang/6f682fe6ca12e02acc1c6af2c67632e7
>
> It needs some polish around the parsing (need to handle 
> parentheses and separating symbols with something other than 
> space), but I'm pretty happy with the concept.
>
> -Steve

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?

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.

Cheers,
- Ali


More information about the Digitalmars-d mailing list