Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Dukc
ajieskola at gmail.com
Thu Jan 28 08:08:49 UTC 2021
On Thursday, 28 January 2021 at 07:44:05 UTC, Walter Bright wrote:
> On 1/27/2021 11:16 PM, Dukc wrote:
>> 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.
>
> Nobody is going to prefer calling printf that way.
>
Yeah, easier to just use `std.stdio.write`.
> Redefining a custom Interp template is a no-go, too, as then
> the code is incompatible with common usage code.
>
I wouldn't like that either.
>
>> 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.
>
> Sounds complicated enough to be a non-starter.
...but on that I disagree. It can be a library function. I am not
sure whether it should be in Phobos, in some DUB package, or just
copy-pasted around, but in any case one would not need to face
the complexity oneself to use it.
More information about the Digitalmars-d
mailing list