Interpolated strings

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 19 03:22:45 PDT 2017


On Wednesday, 19 April 2017 at 00:08:19 UTC, Walter Bright wrote:
> There are additional problems, such as:
>
>     $"{a} in %s {b}"

% should be escaped: "%s in %%s %s". There would be no use for a 
single % otherwise.

> and positional parameters:
>
>     $"{a} in {0}"

That would be literal 0: `"%s in %s", a, 0`. Could be disallowed 
but maybe not important.

Presumably braces would be escaped $"\{ \}" -> "{ }". Also having 
no {code} block in an interpolated string should be an error.

I like the simplicity of the lowering but it doesn't have much 
advantage over text(a, " in ", b), you still have to import a 
function. I suppose the advantage is readability for longer 
strings.

Also, there are compile-time tricks to make formatting more 
efficient with a compile time format string - e.g. format!"%s in 
%s"(true, null). Here format can know the length of the resulting 
string. With your lowering format can't receive the format string 
as a compile-time argument.


More information about the Digitalmars-d mailing list