Interpolated strings

Kapps via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 17 12:38:33 PDT 2017


On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote:
> Hi all
>
>   I've been wanting to have support for interpolated strings in 
> D for some time now that will allow you to write e.g.:
>
> auto a = 7;
> writeln( $"{a} times 3 is {a*3}" );
>
> Code speaks louder that words so I've made a PR that adds this 
> support to ddmd as a RFC [1].
>
> The compiler will basically lower the $"..." string to a mixin 
> that concatenates
> the expression parts of the (inside the {}) and the plain text 
> parts.
>
> I do recognize that this is not part of the 2017 H1 plan but I 
> also believe such smaller improvements added regularly can make 
> the language both more productive and attractive.
>
> In case this addition gets a thumbs up I will of course improve 
> test coverage and any needed quality of implementation.
>
> [1] https://github.com/dlang/dmd/pull/6703

C# got this feature recently. I didn't expect it to be a 
significant difference, but I do find it a substantial 
improvement. Not only does it clearly show what goes where, but 
it's so much cleaner and more convenient.


More information about the Digitalmars-d mailing list