Interpolated strings
crimaniak via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 17 06:12:35 PDT 2017
On Sunday, 16 April 2017 at 16:10:15 UTC, Nick Sabalausky
(Abscissa) wrote:
> Yea, and note, I'm still open to the idea of better names than
> "interp". I'm still not entirely happy with that name. I'm even
> half-tempted to use "_".
When I needed interpolation, I did not know about this library.
So I create my own implementation and name it `expand`. I only
needed class properties and did not support the expression, so
this can not be considered a general solution, but name `expand`
seems to be good for me.
unittest
{
class InterTest
{
static int a = 1;
static string bb = "--bb--";
mixin ExpandLocals;
auto getInterpolated()
{
return expand!"a is $a, bb is $bb, and this is just $ sign";
}
}
assert((new InterTest).getInterpolated() == "a is 1, bb is
--bb--, and this is just $ sign");
}
> What I think would be ideal is a language enhancement to allow
> "interp" to do its job without the extra syntactical noise.
> That would not only give us good interpolates strings, but
> would likely have other applications as well.
Now I spend thinking some time about it and didn't find common
solution without text mixin too.
More information about the Digitalmars-d
mailing list