DIP 1027---String Interpolation---Format Assessment

Adam D. Ruppe destructionator at gmail.com
Thu Feb 27 15:12:23 UTC 2020

On Thursday, 27 February 2020 at 14:47:55 UTC, SealabJaster wrote:
> At that point, it begs the question of why even bother having 
> string interpolation.

I encourage you to read my document too:


It addresses all these concerns. Walter's proposal is dead. It 
has been formally rejected. We shouldn't waste more time talking 
about it.

> I'd like to imagine that most newcomers/returning veterans of D 
> would see "D has string interpolation!" and then expect it to 
> work similar to how it does in most other languages.

My proposal doesn't work exactly like in other languages - it is 
uniquely D so we don't waste our potential. It does everything C# 
can do, except the implicit conversion to string... BUT, if you 
assume it is the same as other languages, you get a compile 
error, and the error message tells you how to convert it to a 
regular string!

f(i"hello $a");

error: cannot implicitly convert argument of type interpolated 
tuple to type string. Tip: use `.idup` to explicitly convert it 
to string.

f(i"hello $a".idup); // works almost like other languages now!

f2(i"hello $a", i"hello $b"); // type mismatch error, try idup

f2(i"hello $a".idup, i"hello $b".idup); // works

So education wise, it is only a few seconds: if you use it like 
in other languages, it doesn't work, but the compiler tells you 
how to fix it.

If you find the error or `.idup` method unacceptable, then... I'm 
sorry, but you aren't going to win that one. We've already argued 
this at length and the community is not willing to lose what we'd 
lose (ref, scope, compile-time usage, and more) by making that 
work; the trade-offs are too steep.

More information about the Digitalmars-d-announce mailing list