Better string mixins
Dgame
r.schuett.1987 at gmail.com
Wed Jan 2 21:54:02 UTC 2019
On Wednesday, 2 January 2019 at 21:06:19 UTC, Bastiaan Veelo
wrote:
> On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
>> Hi, I've played around with string interpolation and wanted to
>> ask if this is somewhat helpful?
>>
>> https://run.dlang.io/is/6AokiH
>
> You are aware of `writefln`?
>
>> writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
>> writefln("a = %s, b = %s, c = %s", a, b, c);
>
> These lines produce the same output.
Yes I do. But consider this:
int c = 3;
int z = c * c;
writefln("%s * %s = %s", c, c, z);
vs
writeln(fmt!("$c * $c = $z", c, z));
Just one c is applied. But I've disovered one slightly error
here, the interpolation variables should be enclosed with { to
prevent mistakenly replacement.
Also, currently no further "magic" as ${c * 2} can't be
interpreted as someone might wish, it is somewhat static, but
I've thought it might be interesting.
More information about the Digitalmars-d
mailing list