D rawkz! -- custom writefln formats
Miles Stoudenmire
miles.stoudenmire at gmail.com
Thu Jan 17 10:33:58 PST 2013
Posted to reddit:
http://www.reddit.com/r/programming/comments/16riz9/creating_custom_print_format_specifiers_in_d/
Wanted to credit H.S. Teoh but wasn't sure how...
On 17 January 2013 10:12, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> On 1/16/13, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
>> // Wait -- what? What on earth are %i, %j, %k, and %l?!
>> writeln("%i", s); // Hmm, prints "i"!
>> writeln("%j", s); // Hmm, prints "j"!
>
> I wish we could write string specifiers rather than char specifiers.
> You can invent your own char specifiers but they're still going to be
> hard to understand at the call site. I would prefer:
>
>> writefln("{fullname}", s);
>> writefln("{type}", s);
>
> And have:
>
> void toString(scope void delegate(const(char)[]) sink,
> FormatSpec!string fmt) const
> {
> switch(fmt.spec)
> {
> case "fullname"
> break;
> case "type":
> break;
> }
> }
>
> We could invent this in our own library but it won't be usable with
> existing format and write functions.
--
-=Miles Stoudenmire=-
miles.stoudenmire at gmail.com
estouden at uci.edu
http://itensor.org/miles/
More information about the Digitalmars-d
mailing list