Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2

Dukc ajieskola at gmail.com
Thu Jan 28 07:16:59 UTC 2021


On Thursday, 28 January 2021 at 06:12:14 UTC, Walter Bright wrote:
> It appears to have abandoned being usable with printf?

Well a simple way is `printf("%s", text(i"hello ${name1}, 
${name2} and {name3}!"))`. Works, but not in a no-gc way unless 
you redefine `Interp!()` yourself.

Even without touching `Interp!()` you could do a function that 
prints an interpolated string with `printf` without using the GC, 
as long as the format specifier is known at compile time. The 
function introspects the received `Interp!string` struct types 
and makes the correct format specifier from them at compile-time 
and feeds it along with rest of the arguments to `printf`. This 
is more complicated of course.


More information about the Digitalmars-d mailing list