Just another example of missing string interpolation

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Wed Oct 18 07:53:03 UTC 2023


On Wednesday, 18 October 2023 at 03:57:52 UTC, Walter Bright 
wrote:
> The line in question:
>
> ```
> writeln(__header, "I ate ", apples, " apples and ", bananas, " 
> bananas totalling ", apples + bananas, " fruit.")
> ```
>
> What does writeln() do with __header?

__header is implicitly converted to null string by writeln (the 
struct will have a toString method that returns null), so from 
the point of view of existing text methods such as writeln, text, 
everything is fine.

> Does that mean writeln() gets rewritten to handle __header? If 
> so, ok, but the YAIDIP doesn't say that.
>
> Today, the only difference between writef() and write() is the 
> former takes the first argument as the format string. Is this a 
> fatal error? I suppose you could consider it as one, but that's 
> an issue typical with variadic functions.
It's a pain to parse it (DIP 1027) when you'd like to define your 
own function accepting interpolated strings, compared to 
suggested DIP.

>> Already did, over an hour ago.
>
> Ok, I saw it after I posted that.
>
>> It took about 30 seconds to specify. This isn't a big deal.
> I think we're misunderstanding each other. What I am asking 
> about is how does the user specify his own custom 
> implementation of InterpolatedExpression?

I think the assumption is that __header type is passed as 
template argument, then there are no issues with voldemort types. 
If you really like to specify type not through template argument, 
I guess DIP could be enhanced saying that __header could 
implicitly convert to a predefined struct, i.e. 
RuntimeStoredInterpolationInfo.

Best regards,
Alexandru.




More information about the Digitalmars-d mailing list