Discussion Thread: DIP 1036--Formatted String Tuple Literals--Community Review Round 1

Adam D. Ruppe destructionator at gmail.com
Fri Sep 11 18:17:10 UTC 2020

On Friday, 11 September 2020 at 17:37:36 UTC, SHOO wrote:
> 2. It doesn't seem to work well with the {} style formatting 
> employed by C#, Rust, etc. Is the following interpretation 
> correct?
> `String.Format("You are now {0} years old.", years - 1)`

You'd do it more like

`String.Format(i"You are now ${{0}}(years - 1) years old.")`

No backslashes. But it isn't really ideal for positional ones 
like that since you'd have to keep the count going right yourself.

At this point you would ideally write an overload to 
String.Format that checks for the interpolation spec then 

The DIP's text as submitted right now makes this unnecessarily 
difficult, so we're gonna reword it. The same implementation 
still works though.

> 3. The object.idup in the DIP uses `import std.format`, is it 
> permissible for the druntime to be dependent on Phobos?

Technically, druntime is still independent. Since it is a 
template, its dependency falls on the user, not the library.

When you compile druntime, that code is completely ignored. It is 
not present in the compiled library and the import is not 

If you use the idup function, the instance appears in *your* code 
and only then is Phobos actually imported. So formally, the 
dependency is on phobos from your code at the use point. So if 
you never use it, there's no dependency.

This is one of D's coolest features to me btw.

> 4. Are there any reasons why backquotes (i`...`) are not 
> allowed?

Trying to just define the simplest thing that can work. D has a 
lot of string types and adding i to each of them is a lot.... All 
these cases are possible with the juxtaposition thing though:

i""`....` would work the same way.

> 5. Although you use the name idup, idup should be used to 
> create `immutable(_d_interpolated_string!Parts)`

There's two pieces to the interpolated tuple: the spec definition 
and the arguments. The _d_interpolated_string!Parts thing is just 
the spec definition. So your example is wrong: you left the 
arguments out. idup makes no sense without combining it.

The main reason for using idup over toString though is just 
reusing an existing global name... it won't break any code since 
it isn't introducing anything new. And since it already works on 
string it has some precedent:

char[] a;
string b = a; // cannot convert, you need to idup it.

string b = i"xxx"; // cannot convert, also need to idup it.

More information about the Digitalmars-d mailing list