[erlang-questions] io:format vs io_lib:format

Maximillian Dornseif md@REDACTED
Sat Aug 25 07:11:38 CEST 2007


I  understand that io:format and io_lib:format are to erlang what printf and
sprintf are to C. So I wonder why I get different results from them. What am
I missing here?

42> [io:format("01-~2.10.0B-01~n", [N])  || N <- lists:seq(1, 3)].
01-01-01
01-02-01
01-03-01
01-04-01
01-05-01
01-06-01
01-07-01
01-08-01
01-09-01
01-10-01
01-11-01
01-12-01
[ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok]
43> [io_lib:format("01-~2.10.0B-01~n", [N])  || N <- lists:seq(1, 12)].
[[48,49,45,["0","1"],45,48,49,"\n"],
 [48,49,45,["0","2"],45,48,49,"\n"],
 [48,49,45,["0","3"],45,48,49,"\n"],
 [48,49,45,["0","4"],45,48,49,"\n"],
 [48,49,45,["0","5"],45,48,49,"\n"],
 [48,49,45,["0","6"],45,48,49,"\n"],
 [48,49,45,["0","7"],45,48,49,"\n"],
 [48,49,45,["0","8"],45,48,49,"\n"],
 [48,49,45,["0","9"],45,48,49,"\n"],
 [48,49,45,"10",45,48,49,"\n"],
 [48,49,45,"11",45,48,49,"\n"],
 [48,49,45,"12",45,48,49,"\n"]]

The obvious solution is to use lists:flatten(io_lib:format(...)) but why?

Regards

Maximillian Dornseif
-- 
View this message in context: http://www.nabble.com/io%3Aformat-vs-io_lib%3Aformat-tf4326912.html#a12323263
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list