[erlang-questions] Pretty printing records
Thu Nov 20 21:25:32 CET 2008
On Thu, Nov 20, 2008 at 05:44:26PM +0100, Ulf Wiger wrote:
} You can use the same function as the shell, namely:
} io_lib_pretty:print(Term, RecDefFun)
That is indeed what I was looking for. The result is a deep
list which when printed using the '~s' control sequence in
io:fwrite/2 (or in my case ct:log/2) gets output nicely.
ct:log("Foo = ~s", [pretty_print(Foo)])
} The RecDefFun can be somewhat generalized through use of
} the exprecs parse transform.
I just used a local fun with the records I was interested in
io_lib_pretty:print(Record, fun pretty_print/2).
pretty_print(foo, N) ->
N = record_info(size, foo) - 1,
pretty_print(bar, N) ->
N = record_info(size, bar) - 1,
pretty_print(_, _) ->
More information about the erlang-questions