On Monday, 23 October 2023 at 14:12:25 UTC, Rumbu wrote:
>On Saturday, 21 October 2023 at 18:59:13 UTC, Adam D Ruppe wrote:
>On Saturday, 21 October 2023 at 18:31:10 UTC, Imperatorn wrote:
>In C# an interpolated string is just a string
This isn't true. It is an object that can convert to string (similar to D's alias toString this;
)
In fact neither, it's syntactic sugar.
int count = 10;
string s = $"I drink {count} beers";
is syntactic sugar for:
int count = 10;
DefaultInterpolationHandler dh = new DefaultInterpolationHandler();
dh.AppendLiteral("I drink ");
dh.AppendFormatted(count);
dh.AppendLiteral(" beers");
string s = dh.ToStringAndClear();
From compiler point of view, Roslyn stores in AST a interpolated string as an array of expressions which get converted before IL compilation to the code above.
I wonder why we can't do this in D, using text() or format() or everything else instead of returning tuples.
Andrea