The state of string interpolation

o o at o.o
Thu Dec 6 22:34:14 UTC 2018


On Thursday, 6 December 2018 at 22:04:13 UTC, Steven 
Schveighoffer wrote:
> [...]
> Now, on top of that, if we do go with the lowering to tuples, 
> we get even more power. We have so many more options than just 
> a simple concatenated string. The DB query possibility makes my 
> mouth water. And I've written a lot of DB queries with D. They 
> are hard to write, and hard to read. Every time I add a stupid 
> column, and then I have to add a new placeholder, and put the 
> new value in the right place in the trailing arguments, it's a 
> long process.
>
> -Steve

While I agree that lowering to tuples opens awesome 
possibilities, it is rather different than string interpolation. 
"string interpolation" should lower to a string, so an 
interpolated string can be used identically to any other string. 
It just makes a lot more sense if an "interpolated string" 
actually is a string, not a tuple.

String interpolation (at least using the 'i' prefix) should 
produce a string. If 'tuple interpolation' really is beneficial, 
maybe it could be added as a different string prefix
i.e `assert(t"my name is $name" == tuple("my name is ", name))`
and `assert(i"my name is $name" == "my name is Jeff")`

Just think how much nicer this is (lowering to a string):
`foo(i"My name is $name");`

Compared to this (lowering to a tuple, requiring a conversion to 
a string):
```
import std.conv: text;
foo(text(i"My name is $name"));
```


More information about the Digitalmars-d mailing list