On Wednesday, 21 March 2012 at 01:26:23 UTC, bearophile wrote:
import std.stdio;
void main() {
auto mat = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]];
writefln("%(%(%d %)\n%)", mat);
writeln();
writefln("[%(%(%d %)\n%)]", mat);
writeln();
w
Andrej Mitrovic:
I didn't know that! Is this documented anywhere?
It's documented formally, but I see no usage examples of the
nested formatting syntax:
http://dlang.org/phobos/std_format.html
Bye,
bearophile
On 3/21/12, bearophile wrote:
> The following is just a note. The formatting syntax for arrays is
> rather powerful, it allows you to pretty print a matrix.
I didn't know that! Is this documented anywhere?
import std.stdio;
void main() {
auto mat = [[1, 2, 3],
[4, 15, 6],
[7, 8, 9]];
writefln("[%([%(%2d, %)],\n %)]]", mat);
}
That outputs:
[[ 1, 2, 3],
[ 4, 15, 6],
[ 7, 8, 9]]
Sorry, the dlang forum online interface has added an extra
leadin
This code:
import std.stdio;
void main() {
auto mat = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]];
writefln("%(%(%d %)\n%)", mat);
writeln();
writefln("[%(%(%d %)\n%)]", mat);
writeln();
writefln("[%([%(%d %)]\n%)]", mat);
writeln();