Wanted: Format character for source code literal

Berni44 someone at somemail.com
Sat May 1 08:19:59 UTC 2021


On Friday, 30 April 2021 at 21:11:55 UTC, H. S. Teoh wrote:
> 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.

Of course, there are limits to this. I intend to implement it for 
bools, integers, floats, characters, strings and enums. I think 
it will also be possible to implement it for (associative) 
arrays, as long as the elements can be implemented like this. 
Structs, classes, interfaces and unions should implement it in 
their `toString` functions. I wouldn't go so far to provide 
generic code for them. With that we'll indeed run into problems. 
(Maybe with the exception of structs with default constructor.) I 
haven't made up my mind about pointers yet.

And well functions, delegates and lambdas? Functions aren't 
supported by `std.format` at all and the implementation of 
delegates is broken and useless and should be removed (in my 
opinion).


More information about the Digitalmars-d mailing list