DIP 1027---String Interpolation---Community Review Round 1
mipri
mipri at minimaltype.com
Tue Dec 17 17:31:20 UTC 2019
On Tuesday, 17 December 2019 at 17:13:50 UTC, Patrick Schluter
wrote:
> 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.
These languages also don't store "interpolated strings" in
variables; they store strings in variables, and any string
interpolation happens at the literal.
Crystal (compiled language with a real type system, etc.):
apple = 0
my_is = "apple=#{apple}"
apple = 36
puts my_is
Ruby (interpreted scripting language):
apple = 0
my_is = "apple=#{apple}"
apple = 36
puts my_is
Both output "apple=0". I can't recall a case where you'd get
"apple=36". You'd have to deliberately delay evaluation of the
literal.
But I don't think anyone's asked for any other behavior than
this. What's wanted is for
int apple;
string my_is = i"apple=$apple";
apple = 36;
writeln(my_is);
to output "apple=36" rather than result in a compile-time
error because i"..." doesn't evaluate to a string.
More information about the Digitalmars-d
mailing list