Interpolated strings
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 18 04:33:57 PDT 2017
On 2017-04-18 10:50, Walter Bright wrote:
> It may not be necessary to have any dependencies on any import.
>
> $"{a} times 3 is {a*3}"
>
> could be rewritten by the parser to:
>
> "%s times 3 is %s", a, a * 3
>
> and that is that. (I.e. just an AST rewrite.) It would be quite a bit
> simpler than Jonas' proposed implementation.
Then you would be forced to wrap it in a function call, to "format" or
similar. The example of using "writeln" is not the best, a more useful
example is when not printing the string immediately. For example:
auto s = $"{a} times 3 is {a*3}";
With your example that would need to be written as:
import std.format;
auto s = format($"{a} times 3 is {a*3}");
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list