[erlang-questions] Pretty printing records
Ulf Wiger
ulf@REDACTED
Thu Nov 20 21:58:56 CET 2008
But I believe the catch-all should be:
pretty_print(_, _) ->
no.
BR,
Ulf W
2008/11/20 Vance Shipley <vances@REDACTED>:
> 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
> seeing:
>
> pretty_print(Record) ->
> io_lib_pretty:print(Record, fun pretty_print/2).
>
> pretty_print(foo, N) ->
> N = record_info(size, foo) - 1,
> record_info(fields, foo);
> pretty_print(bar, N) ->
> N = record_info(size, bar) - 1,
> record_info(fields, bar);
> pretty_print(_, _) ->
> [].
>
> Thanks,
>
> -Vance
>
More information about the erlang-questions
mailing list