String Interpolation Compare - DIP1027 and YAIDIP

Steven Schveighoffer schveiguy at gmail.com
Sat Oct 21 04:54:16 UTC 2023


On Saturday, 21 October 2023 at 04:17:57 UTC, Walter Bright wrote:
> On 10/20/2023 8:51 PM, Steven Schveighoffer wrote:
>> How can you possibly think that YAIDIP requires allocations?
>
> How else can you make a user-defined dec() work?

I'm not sure I understand this. What is `dec()`?

>
>
>> The only proposal that requires allocations is DIP1027, since 
>> you must rebuild the format string if your function doesn't 
>> support printf style format specifiers (i.e. mysql).
>
> The example I gave in the other thread shows how to not need to 
> rewrite the format string.
>
> https://www.digitalmars.com/d/archives/digitalmars/D/Just_another_example_of_missing_string_interpolation_370542.html#N370696

mysql requires a string as the sql for the prepared statement. 
Basically, you pass a string with a different type of placeholder 
specifier "?". It does not accept "%s". This is not something I 
have any control over.

So naturally, since you only get a runtime format string from 
DIP1027, you need to create an equivalent runtime string to pass 
to the library. How can you do that without allocations?

>
> But even if you did rewrite it, it doesn't escape the template 
> function, and can be RAII'd.

That is not comparable to building the correct string at 
compile-time. It also requires *parsing* the format string at 
runtime.

>
> Dealing with a string allocated and returned by `dec()` is 
> significantly harder.

You will have to expand on what `dec()` is, I'm unfamiliar with 
it.

-Steve


More information about the Digitalmars-d mailing list