String interpolation, after a healthy debate on discord

Steven Schveighoffer schveiguy at
Tue Dec 14 15:49:52 UTC 2021

On 12/14/21 6:15 AM, WebFreak001 wrote:
> On Tuesday, 14 December 2021 at 11:02:58 UTC, Ogi wrote:
>> On Tuesday, 14 December 2021 at 09:35:27 UTC, WebFreak001 wrote:
>>> 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.
>> I was referring to YAIDIP. According to it, istring should be allowed 
>> in `mixin`, `pragma(msg)` and `assert` (missed this one). This 
>> requires reimplementing `text` in the compiler.

pramga(msg) and mixin do not need implementations of `std.conv.text`.

`pragma(msg, "x = ", x);` already works, just need it to ignore the header.

`mixin("int y = ", x + 5, ";")` already works, just need it to ignore 
the header.

assert would need some implementation of runtime output. But it's 
already in the library with `-checkaction=context`. It just needs to be 

> ah right you mean for the built-in istring usage in the compiler it 
> needs to be implemented.
> I don't think it's such a big problem though, as the phobos 
> implementation would also just be: (a little simplified)
> ```d
> auto text(istring...)(istring s) if (isIString!istring)
> {
>      return text(s[1 .. $]); // removes special __header, just 
> concatenate rest
> }
> ```

The DIP is designed specifically to work with `text` as-is. You don't 
need a special overload (because the header has a `toString` that 
returns ""). This was inherited from our DIP.

As for the specialized call syntax, I don't think we need it.

As for implementing some `text`-like thing in druntime, we already have 
some of it, I think it would be reasonable to include something in 
object.d that does a straightforward conversion when you don't want to 
use std.format. The only complex one is floating point. This all can be 
done AFTER the DIP is accepted anyway.


More information about the Digitalmars-d mailing list