DIP 1027---String Interpolation---Format Assessment

Juraj Mojzis mojo at frikulin.sk
Wed Feb 26 10:02:15 UTC 2020


On Wednesday, 26 February 2020 at 09:45:55 UTC, Walter Bright 
wrote:
>> void f(string s, int i = 0);
>> f(i"hello $a"); // silent unwanted bahviour.
>> 
>> ?
>
> It is lowered to:
>
>   f("hello %s", a);
>
> as designed. I don't know what's unwanted about it.

void print_many(string msg, int cnt = 1) {
     foreach(i; 0 .. cnt) writeln(msg);
}

int apple_cnt = 4;
print_many(i"I have $apple_cnt apples.");

expected: I have 4 apples.
real (unwanted) output:
I have 4 apples.
I have 4 apples.
I have 4 apples.
I have 4 apples.


More information about the Digitalmars-d-announce mailing list