DIP 1027---String Interpolation---Community Review Round 1

Patrick Schluter Patrick.Schluter at bbox.fr
Mon Dec 16 12:43:04 UTC 2019

On Monday, 16 December 2019 at 11:38:34 UTC, aliak wrote:
> On Monday, 16 December 2019 at 11:08:00 UTC, Patrick Schluter 
> wrote:
>> On Monday, 16 December 2019 at 10:48:51 UTC, aliak wrote:
>>> [...]
>> because
>> string s = ("%s",var);
>> is a syntax error.
> Exactly. And then explain why. And what is that thing on the 
> right. And why is string assignment not working on an 
> interpolated _string_?
>> Even a beginning programmer can understand that an 
>> interpolated string cannot be a pure simple string as it 
>> contains symbols and expressions that are language construct 
>> not part of the string literal, i.e. that the compiler has to 
>> perform some transformations to substitute these language 
>> symbols into a value.
>> Interpolated strings, in any language, are not string literals.
> In any language, they can be assigned to strings.

Not true for some languages I checked

- C# and Kotlin do the resolution at runtime and the interpolated 
string is not a string and has to be converted with .toString 
which is equivalent in calling .format in D.
- Rust and Java do not have interpolated strings
- Swift I don't know. Looks powerful but in a whole different 
difficulty level.

all others are interpreters python, perl, ruby, bash, tcl, VB, 
PHP etc. for whom it is much easier as there is no distinction 
between CT and RT.

>> Each language resolves this fact in different manners and at 
>> different times. Interpreted languages do it at runtime 
>> (obviously), java like languages chose to do it at runtime. In 
>> a language like D, which prefers resolving what is resolvable 
>> at compile time, it would be loathed if it interpolation was 
>> resolved at runtime (remember how long people were bitching 
>> about runtime only format strings?)
>> Resolving interpolation at compile time is imho incompatible 
>> with handling them as regular strings.
>> The question is then do we want CT or RT interpolated strings. 
>> RT interpolated strings can still be provided by a library.
> See Adam's previous posts on his approach.
// Use reduce to calculate the sum
     // of all squares in parallel.
     auto result = taskPool.reduce!"a+b"(
         0.0, iota(100).map!"a*a");
     writeln("Sum of squares: ", result);

More information about the Digitalmars-d mailing list