String interpolation, after a healthy debate on discord

WebFreak001 d.forum at webfreak.org
Tue Dec 14 09:35:27 UTC 2021


On Tuesday, 14 December 2021 at 09:10:07 UTC, Ogi wrote:
> On Friday, 10 December 2021 at 18:39:32 UTC, WebFreak001 wrote:
>> if that's your pain point, check out this proposal here: 
>> https://forum.dlang.org/thread/kivjspiezjvqxjkhiugj@forum.dlang.org :)
>
> It’s not just my pain point though. We need to convert stuff to 
> strings all the time. For example, every time we want a 
> meaningful message in an assertion or an exception. Many Phobos 
> modules have to import `std.format` or `std.conv` just for that.
>
> To my understanding, this proposal already requires moving 
> `text` functionality into compiler (if it’s not there already, 
> I don’t know). So why not just make one more step forward and 
> allow converting istrings to strings? If implicit conversion is 
> too much to ask for, it could be an explicit cast to string, or 
> some property. Maybe `stringof` should do exactly that?

no this proposal does not suggest moving any functionality into 
the compiler. It suggests to add the istrings (tuples with 
header) as described in the YAIDIP and have special function 
calling syntax (`functionName"istring contents"`) that will call 
any function, that accepts an istring as only argument. The 
`text` function from `std.conv` would implement an overload 
accepting an istring, which can then be called `text"istring 
contents"` (same as `text(i"istring contents")`) and be the 
idiomatic string building function using the GC.

Then with the other linked proposal you could add `std.conv` (or 
a custom wrapper that only imports `std.conv:text`, maybe 
aliased) as default-import to all files in your project, so you 
can just type `text"istring contents"` to make strings without 
needing to import std.conv anywhere.


More information about the Digitalmars-d mailing list