[erlang-questions] Why io::format() type is not an iolist?

44 views
Skip to first unread message

Aleksandr Vinokurov

unread,
Aug 9, 2012, 3:45:02 AM8/9/12
to erlang-q...@erlang.org


Hello all

I've found the subject and did not understand the root of such restriction: why io:format/2 can't understand iolist for a Format arg?

WBR,
--
Александр Винокуров
@aleksandrvin

Richard Carlsson

unread,
Aug 15, 2012, 3:03:57 PM8/15/12
to erlang-q...@erlang.org
On 08/09/2012 10:45 AM, Aleksandr Vinokurov wrote:
>
>
> Hello all
>
> I've found the subject and did not understand the root of such
> restriction: why io:format/2 can't understand iolist for a Format arg?

In order to interpret the Format argument, it would need to flatten the
iolist first anyway. For example, io:format(["~",[<<"w">>]], [Term]).
It's simply easier from the library's point of view to just say that the
Format argument needs to be a flat string (guaranteeing that there's no
needless overhead for flattening in the majority of cases), and if you
have an iolist, then define your own format function like this:

format(IOList, Args) ->
io:format(binary_to_list(erlang:iolist_to_binary(IOList)), Args).


/Richard

_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Reply all
Reply to author
Forward
0 new messages