String Interpolation Compare - DIP1027 and YAIDIP
Steven Schveighoffer
schveiguy at gmail.com
Sat Oct 21 04:42:57 UTC 2023
On Saturday, 21 October 2023 at 04:10:35 UTC, Walter Bright wrote:
> On 10/20/2023 8:51 PM, Steven Schveighoffer wrote:
>> Not even printf works as expected, only writef.
>>
>> Try doing printf with a string parameter (not a string
>> literal) with DIP1027.
>
> To use printf with i-strings, it's implicitly necessary to use
> arguments that are compatible with printf. That means
> const(char)* arguments, not string arguments. This is something
> that should be obvious once how i-string conversion to tuples
> works.
>
> DIP1027 has zero knowledge of `writef` or `printf` or `format`.
Yes and no. It's very clearly geared towards writef (or else we
would have some other default other than %s), even though it
doesn't require hooking with writef. But in effect, writef and
format (and other functions like it, such as loggers) are the
only functions it works with "out of the box". There are many
other functions that use the same style of "blueprint + data"
calls which will utterly fail, and can't be made to work with
DIP1027.
BTW, I count a failure as having to specify the correct
substitution as the user. That is the domain of the function or
the type system.
> --- However ---
>
> Ever since we added printf format checking to the language,
> I've toyed with the idea of going a step further and adjusting
> the arguments (and formats) of the calls to printf to make them
> work.
Nobody, and I really truly mean, NOBODY, is clamoring for better
ways to call printf (specifically printf).
And if you are, YAIDIP or DIP1036 is your guy. It can do it,
without any specialized compiler help, without allocations, and
in betterC mode (as I have demonstrated).
-Steve
More information about the Digitalmars-d
mailing list