DIP 1027---String Interpolation---Community Review Round 1
Patrick Schluter
Patrick.Schluter at bbox.fr
Tue Dec 17 17:13:50 UTC 2019
On Tuesday, 17 December 2019 at 16:43:32 UTC, Jacob Carlborg
wrote:
> 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.
Which was my point. An interpolated string cannot be stored in a
simple string as some people requested in the thread before (not
you). It is only feasible if the istring is evaluated at runtime
with an interpreter who knows the current values of the variables
used. Interpreted languages like python, perl, javascript etc.
might get away with it but compiled languages have to transform
it in its code representation.
>
>> 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.
More information about the Digitalmars-d
mailing list