The state of string interpolation

Claude no at
Mon Dec 10 10:30:40 UTC 2018

On Thursday, 6 December 2018 at 00:32:48 UTC, Adam D. Ruppe wrote:
> On Thursday, 6 December 2018 at 00:20:53 UTC, H. S. Teoh wrote:
>> Why can't this be added to to as a library / 
>> dub package / whatever?
> Library things cannot access the local scope of the string 
> unless you mixin.
> So
> mixin(interp!"foo #{a}");
> is doable as a library (and I know Nick Sabalusky's scriptlike 
> has it, probably among others), but
> string b = "foo #{a}";
> is only doable as a language feature.

I have some syntax suggestion...

Interpolated string would fit well with string-mixins. I 
sometimes tend to use the following pattern:

         enum densityToBitmap(int x, int y, int z) =
                 if (length(%d, %d, %d) <= 0)
                     index |= (1 << cornerIds[%d][%d][%d]);
             }.format(x, y, z, x, y, z);

         mixin(densityToBitmap!(0, 0, 0));
         mixin(densityToBitmap!(0, 0, 1));
         // etc ...

So I use the q{ ... } syntax when the string contains D code to 
be "mixed-in" later. Using "format" is a bit awkward, so 
interpolated strings would help to make the code more readable, 
and we could still keep the braces-syntax.

For example, replacing the "q{ ... }.format(...)" by a "i{ ... 

More information about the Digitalmars-d mailing list