D rawkz! -- custom writefln formats

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Jan 17 10:12:56 PST 2013


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.


More information about the Digitalmars-d mailing list