[erlang-questions] Pretty printing records from a program

Ulf Wiger (TN/EAB) <>
Thu Sep 28 18:59:38 CEST 2006

So how about this post then?
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)),
    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.

Ulf W

(Next time, I hope to contribute something that _isn't_ a parse


[mailto:] On Behalf Of Joe Armstrong
	Sent: den 28 september 2006 15:30
	Subject: [erlang-questions] Pretty printing records from a
	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 
	But was none the wiser

More information about the erlang-questions mailing list