DIP 1027---String Interpolation---Community Review Round 1

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 17 17:31:05 UTC 2019


On 12/17/19 12:19 PM, ag0aep6g wrote:
> On 17.12.19 18:12, Steven Schveighoffer wrote:

>> Is there a way that this could work? I mean, aside from storing 
>> lambdas for everything?
> 
> alias as = AliasSeq!("%s apples and %s bananas", apples, bananas);

:facepalm:

Thanks!

That is pretty cool. Coupled with a logging function:


     import std.experimental.logger;
     int apples = 5;
     int bananas = 6;
     //equivalent to: alias msg = i"$apples apples and $bananas bananas";
     alias msg = AliasSeq!("%s apples and %s bananas", apples, bananas);
     logf(msg);
     ++apples;
     ++bananas;
     logf(msg);

This works pretty well, shows the filename/line numbers, and reevaluates 
the log message each time.

Another cool use case.

-Steve


More information about the Digitalmars-d mailing list