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

Meta jared771 at gmail.com
Tue Dec 17 18:17:30 UTC 2019


On Tuesday, 17 December 2019 at 17:31:05 UTC, Steven 
Schveighoffer wrote:
> 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

This got me excited, but unfortunately it doesn't work with 
expressions (for obvious reasons):

// Error: variable apples cannot be read at compile time
alias msg = AliasSeq!("%s apples and %s bananas makes %s fruit", 
apples, bananas, apples + bananas);



More information about the Digitalmars-d mailing list