Just another example of missing string interpolation

Walter Bright newshound2 at digitalmars.com
Fri Oct 20 08:03:55 UTC 2023


On 10/19/2023 6:52 PM, Steven Schveighoffer wrote:
> The point is that it's too easy to match to strings, compile, and do a 
> completely unexpected thing. And yes, that's the major reason why 1027 is so bad.

I don't recall this issue even being discussed in the old review of it. It isn't 
listed in the review objections for DIP1027.

https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md#description

If you can point the discussion out to me, I'd appreciate it.

But I undestand you don't like this, and there is a rather nice solution. Recall 
Andrea Fontana's example:

```
void deleteFiles(string[]... files) { ... }
```

As a special case, an i-string will not be a match for `string[]...`. This makes 
sense, as a function requiring a format string would not be expecting no string. 
A match would have to be of the form:

```
void deleteFiles(string fmt, ...) { ... }
```

which is the natural form a formatting function would take. If the user wanted 
to use i-strings to pass to `deleteFiles(string[]...)`, he'd use:

```
string dirname = "project";
string file = "main.o";
deleteFiles(format(i"/tmp/$dirname/$file"));
```

which looks rather nice and self-evident. Hope you like it!




More information about the Digitalmars-d mailing list