DIP1027 + Design by Introspection
Adam D. Ruppe
destructionator at gmail.com
Tue Feb 2 16:57:36 UTC 2021
On Tuesday, 2 February 2021 at 15:55:23 UTC, Daniel N wrote:
> Since DIP1027 is simpler than DIP1036
This is a myth, with the exception of the implicit to string
conversion.
DIP 1027 had to break up the string and reconstruct a new one
while reordering the tuple.
DIP 1036 is a direct syntax rewrite. It just splits the string on
the ${ character into a tuple and puts a simple struct wrapper
around the string parts so you can identify them. See for
yourself how simple the diff is:
https://github.com/dlang/dmd/compare/master...adamdruppe:string_interp
The implicit to string part isn't implemented (gotta figure out
how to express `alias toString this;` inside the compiler
basically, it might be easy but I don't know how).
> Key insight, the function specifies what format it expects.
> printf(...) @formatting!printf_style
> writefln(...) @formatting!writefln_style
DIP 1036 can do this as it is already written! You don't need a
magic UDA, you just overload the function on the interp type as a
library author.
Or you can simply call a function inside the interpolation thing
if you want to do custom stuff as a user.
More information about the Digitalmars-d
mailing list