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

Jacob Carlborg doob at me.com
Fri Feb 28 10:17:11 UTC 2020

On Friday, 28 February 2020 at 03:10:48 UTC, Walter Bright wrote:

> I don't know Swift, but this looks like the "generate strings 
> and concatenate them" approach.

No, it basically lowers to bunch of method calls. Here's an 
example of how it could look like with D syntax:

auto a = 3;
auto b = i"foo $a bar";

Could be lowered to:

auto _temp = StringInterpolation(8 /* literal capacity */, 1 /* 
interpolation count */);
_temp.appendLiteral("foo ");
_temp.appendLiteral(" bar");
auto b = _temp.toString();

There's nothing here that says that this needs to use the GC to 
allocate the final string. "StringInterpolation" could contain 
something like OutBuffer from DMD or, if the arguments were 
passed as template arguments, it could allocate on the stack.

/Jacob Carlborg

More information about the Digitalmars-d-announce mailing list