DIP 1027---String Interpolation---Community Review Round 1
Jacob Carlborg
doob at me.com
Tue Dec 17 16:43:32 UTC 2019
On 2019-12-17 11:14, Patrick Schluter wrote:
> Yes, and that was the point of the exercice. Transforming the
> interpolated "string" into a string evaluates the values of the
> variables at the moment of that transformation. From then on, there is
> no interpolation possible as it a simple string.
> I suppose that what aliak leant in his comments was that the string then
> could still be used for interpolation.
>
> hypothetic scenario of what I interpreted what aliak wanted (and it
> won't compile, it's just for illustration)
>
> int apple;
> ...
> string my_is = i"apple=${apple}";
>
> ...
>
> apple = 36;
> writeln(my_is);
>
> would print "apple=36"
>
> with this DIP, when you do this
>
> int apple;
> ...
> string my_is = i"apple=${apple}".format;
>
> ...
>
> apple = 36;
> writeln(my_is);
>
> will print "apple=0" because my_is will contain the string "apple=0"
I don't see how lowering to a tuple will change anything. It's not
possible to store expressions. If you have the expression `3 + 4` than
that will be evaluated and `7` is what's left. Unless the expression is
wrapped in a lambda.
> The basic thing here is what Walter said above:
>
> interpolated strings are not string literals, they can't be. They are code.
Of course they can. They can be whatever we decide them to be.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list