DIP1027 + Design by Introspection
Daniel N
no at public.email
Tue Feb 2 15:55:23 UTC 2021
DIP1027 + Design by Introspection
Since DIP1027 is simpler than DIP1036 I wanted to take a step
back and see what could be done to fix DIP1027 to be even better
than DIP1036.
1) q{} is designed for code generation it needs to be supported
with Interpolation.
2) DbI
IMHO both DIP1027 and DIP1036 suffers when trying to support
custom formatting...
which makes the syntax as hard to read as the original manual
writefln format string.
My DIP1027+ proposal is based on UDA and can support any function
with trivial syntax.
printf(i"I ate $apples and $bananas totalling $(apples +
bananas) fruit.");
writefln(i"I ate $apples and $bananas totalling $(apples +
bananas) fruit.");
Key insight, the function specifies what format it expects.
printf(...) @formatting!printf_style
writefln(...) @formatting!writefln_style
This way it doesn't have to be repeated in user-facing code over
and over.
Basically the compiler will invoke "printf_style!int" and the
function will return "%d",
the compiler doesn't know anything about printf, it will just
introspect/ask the function.
More information about the Digitalmars-d
mailing list