On 4/15/17 10:04 PM, 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.
Just a quick comment - I would be more interested if the string
interpolation was extendable by the user. A simple path would be to make
string interpolation produce AliasSeq of interleaved pieces of string
with the arguments.
So in your example
writeln($"{a} times 3 is {a*3}")
lowers to
writeln(AliasSeq!(a, " times 3 is ", a*3));
which is basically
writeln(a, " times 3 is ", a*3);
but notice how depending on the function it can be used for other things
such as DSLs.
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
---
Dmitry Olshansky