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

Jacob Carlborg doob at me.com
Mon Dec 16 12:37:47 UTC 2019


On Monday, 16 December 2019 at 11:18:33 UTC, Patrick Schluter 
wrote:

> 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)
>   fn(inter);
>
> ---
> module fn;
>
> void fn(string s)
> {
>   writefln(s);
> }
>
> How would that work?
>
> In python or javascript there's no issue, a is a runtime symbol.

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.

--
/Jacob Carlborg


More information about the Digitalmars-d mailing list