[OT] C# can do all the interpolated strings now

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 8 16:46:31 UTC 2021


On 12/8/21 10:39 AM, WebFreak001 wrote:
> On Wednesday, 8 December 2021 at 13:28:33 UTC, Dennis wrote:
>> On Wednesday, 8 December 2021 at 12:55:02 UTC, Adam D Ruppe wrote:
>>> there's another good document mostly written but waiting on john and 
>>> andrei to take the next step.........
>>
>> https://github.com/John-Colvin/YAIDIP
> 
> ah yeah I couldn't remember where that one was, I only found the 2 other 
> DIPs while googling.
> 
> I like the overall idea but there is one thing that feels a little bad 
> with that: If I have a function
> 
> ```d
> void foo(string header, string docs);
> ```
> 
> I can't just pass
> 
> ```d
> foo(i"$name's Website", i"Welcome on $name's Website");
> ```
> 
> because interpolated strings are not strings. I would need an extra 
> .text call.

I think as long as the call to default-interpolate to a string is 
somewhere at hand (like in object.d), then it's already a win.

My current problem with the status quo is not just that I have to 
reformat the string to have ugly printf style codes in it, but that I 
also have to now add an import somewhere.

> I think it would be easier on users if it was all one big struct like 
> `InterpolatedString!(args here...)` - not being able to be multiple 
> arguments at once

Being a struct means it has to copy the data, which may not be desirable.

> Otherwise if you had `void foo(T...)(T args)` you could no longer 
> iterate over every argument individually, but need to keep track of 
> state to know whether you are in an interpolated string. (and you don't 
> know when it ends)

You do, because the first parameter tells you.

https://github.com/John-Colvin/YAIDIP#the-interpolation-header

-Steve


More information about the Digitalmars-d mailing list