Better string mixins

drug drug2004 at bk.ru
Fri Dec 28 13:07:10 UTC 2018


On 28.12.2018 15:51, rikki cattermole wrote:
> On 29/12/2018 1:43 AM, SashaGreat wrote:
>> On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole wrote:
>>> No need.
>>>
>>> import std.stdio;
>>> import std.format;
>>>
>>> void main() {
>>>     int x;
>>>     mixin("x = %d;".format(8));
>>>     writeln(x);
>>> }
>>
>> Yes, but for the second case it would be ugly...
>>
>> mixin("x = {0}; y = {1}", x, y);
>>
>> S.
> 
> mixin("x = %d; y = %d;".format(8, 4));
> 
> Looks ok to me, given that the original code was ugly as well (it can be 
> improved as a multi-line string).

In practice your mixin string is more complex and format doesn't work so 
nicely. Sometimes you need to use one argument in several places in 
mixin string also. But for the case above it works nice sure.


More information about the Digitalmars-d mailing list