[erlang-questions] Function to print a record with fieldnames?

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Tue Mar 4 15:38:16 CET 2008


Convey Christian J NPRI skrev:
> I've got a record definition along the lines of:  -record(myrec, {foo = undefined, bar=undefined}).
> 
> To help with debugging, I'd like a function that will print out something like the following text:
>    #record{foo = 42, bar = the_answer_to_the_question}
> 
> Does such a function exist, or must I write my own version of the function for each record type?  I know I can just use io:format("~p~n", [ MyRecord ]), but I'd really like the fieldnames to also be printed.

There is such a function - almost (it's not documented, and may not do 
exactly what you want).

I wrote about it a while back in my blog:

http://ulf.wiger.net/weblog/2007/11/20/extending-the-erlang-shell-part-1/

BR,
Ulf W



More information about the erlang-questions mailing list