[erlang-questions] io_lib format inconsistancies

Andrew Thompson andrew@REDACTED
Fri Sep 7 21:03:29 CEST 2012

I wrote a quickcheck test for lager to compare its formatting to io_lib,
and I found a bunch of dissimilarities. However, a couple of the things
I found didn't make a lot of sense, so I figured I'd ask here for an

First one:

1> io:format("~P", [<<>>, 1]).
2> io:format("~W", [<<>>, 1]).
3> io:format("~P", [<<1>>, 1]).
4> io:format("~W", [<<1>>, 1]).

As you can see, ~P and ~W behave differently on the empty binary, but
behave the same when the binary isn't empty. Seems a bit weird.

The other one that bothers me:

16> io:format("~P", ['hello world', 2]).
'hello world'ok
17> io:format("~P", ["hello world", 2]).
"hello world"ok
18> io:format("~P", [<<"hello world">>, 2]).
19> io:format("~W", ['hello world', 2]).
'hello world'ok
20> io:format("~W", ["hello world", 2]).
21> io:format("~W", [<<"hello world">>, 2]).

Why does a 'depth' of 2 mean we print the <<>> and the first *four*
characters of a binary? ~W behaves much more logically. Also why does
depth not apply to printable lists, but it does to binaries?

I've got a branch now for lager to be compatible with this madness, but
I wondered if anyone knows *why* things are like this?



More information about the erlang-questions mailing list