[erlang-questions] Pretty printing records from a program
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Thu Sep 28 18:59:38 CEST 2006
So how about this post then?
http://www.erlang.org/ml-archive/erlang-questions/200605/msg00377.html
I made a small modification and posted a new version in the User
Contributions forum at trapexit.org.
An example of a pretty-print function for your records would then be:
pp(Rec) ->
RF = fun(R,L) when R == element(1,Rec) ->
Flds = '#info-'(Rec),
true = (L == length(Flds)),
Flds
end,
io:fwrite([io_lib_pretty:print(Rec, RF),"\n"]).
The function '#info-'/1 is an introspective function returning a list of
attribute names for the given record - provided that the argument is of
one of the exported record types.
BR,
Ulf W
(Next time, I hope to contribute something that _isn't_ a parse
transform...)
________________________________
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Joe Armstrong
Sent: den 28 september 2006 15:30
To: erlang-questions@REDACTED
Subject: [erlang-questions] Pretty printing records from a
program
I have a record X in a program and all the .hrl files etc.
How do I pretty print this from a program
I know I can do it in the shell with
> rr("*.hrl"),
> rp(X).
But I want to do this from my program
I have read
http://www.erlang.org/ml-archive/erlang-questions/200508/msg00140.html
But was none the wiser
/Joe
More information about the erlang-questions
mailing list