DIP 1027---String Interpolation---Community Review Round 1
Patrick.Schluter at bbox.fr
Mon Dec 16 12:55:17 UTC 2019
On Monday, 16 December 2019 at 12:37:47 UTC, Jacob Carlborg wrote:
> On Monday, 16 December 2019 at 11:18:33 UTC, Patrick Schluter
>> Maybe I'm wrong here, I haven't thought it through, but in
>> first approach I think that's an essential point. As the
>> string contains code, if evaluated at CT, the string must be
>> split somehow in literal parts and code parts. Allowing the
>> i-string to be handled as regular string implies that the
>> splitting happens sometime between when it is declared and
>> after it is used, which can happen after runtime.
>> import fn;
>> int b = 20;
>> string inter = i"$(a+b)";
>> foreach(a; 1..10)
>> module fn;
>> void fn(string s)
>> How would that work?
> Not sure how other languages do it but in Ruby the
> interpolation is performed where the string literal is
> declared. Not where the string is later used. So the above
> would fail because `a` is not available.
Yes, probably. The issue I had with the transformation as string
is what should the code below print?
int a, b = 20;
string inter = i"$(a+b)";
for(a=0; a<10; a++)
void fn(string s)
and that's the difference between CT evaluation and RT evaluation.
More information about the Digitalmars-d