Wanted: Format character for source code literal
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Apr 30 21:11:55 UTC 2021
On Fri, Apr 30, 2021 at 07:10:38AM +0000, Berni44 via Digitalmars-d wrote:
> I plan to add an extension to `std.format`, namely a new format
> character with the meaning of producing a source code literal. Or more
> formally, the following snippet should work for every type this
> extension will support:
>
> ```
> enum a = <something>;
> enum b = mixin(format!"%S"(a));
>
> static assert(a == b && is(typeof(a) == typeof(b)));
> ```
[...]
What's the scope of this feature? Can <something> be, say, a code
literal like a lambda? Can std.format even support printing the function
body of a lambda in a way that can be parsed by mixin()? How far do we
intend to go with this? Or does this only apply to POD values?
I can imagine there'd be problems if you have, say, a class from a
different module with private members, possibly with nested private
classes, so you couldn't actually reconstruct the class instance from a
string alone.
Unless the scope is significantly constrained, I see the potential for
this feature devolving into a big time-sink that really only caters to a
niche use-case. I'd be happy to be proven wrong, though.
T
--
"You know, maybe we don't *need* enemies." "Yeah, best friends are about all I can take." -- Calvin & Hobbes
More information about the Digitalmars-d
mailing list