DIP 1027---String Interpolation---Format Assessment
Adam D. Ruppe
destructionator at gmail.com
Thu Feb 27 14:58:20 UTC 2020
On Thursday, 27 February 2020 at 14:32:29 UTC, Petar Kirov
[ZombineDev] wrote:
> 2. Have the new type implicitly convert to printf-style args. I
> think this is what Adam is proposing. While nice to have, I
> don't think it's necessary.
You can read my document for more detail
https://github.com/dlang/DIPs/pull/186
But basically
writefln(i"hi $name, you are visitor ${%2d}(count)");
gets turned into:
writefln(
// the format string is represented by this type
new_type!("hi ", spec(null), ", you are visitor ",
spec("%2d"))(),
// then the referenced arguments are passed as a tuple
name,
count
)
So very, very, very similar to Walter's proposal, just instead of
the compiler generating the format string as a plain string, the
format string is represented by a new type, defined by the spec
and implemented by druntime. As a result, no more guess work - it
is clear that this is meant to be interpreted as a format string.
It is clear which parts are placeholders/specifiers for which
arguments.
More information about the Digitalmars-d-announce
mailing list