rr(Mod) in the shell

Claes Wikstom <>
Wed Sep 7 13:10:14 CEST 2005



I've become totally and completely addicted to the
feature of the shell where rr(Mod) in the shell reads the record
defs of the Module and displays the records nicely in the shell.

It would be very nice if also records could be nicely printed by
io:format so we could get nice record printouts in logs. Our
logs are widely populated by ugly record printouts.

I've patched shell.erl and io_lib_format.erl to accomplish
this. The format char for records is ~r (ofcource)

I'm not claiming that I understand the code in io_lib
but if you all think that this is also a nice fetaure, maybe
someone who understands the io_lib code better than me
could do it properly.


As an example, as session from the shell:

()3> [P] = mnesia:dirty_read({person, 6003310130}).
[{person,6003310130,
          "Claes",
          "Wikstrom",
          {addr,[],"Malarhojdsvagen 5a",98765,"Stockholm",[],[],[]},
          [],
          [],
          [],
          [{53,"247332"}],
          0,
          [{4,63279658768},
           {2,63292552384},
           {5,63280394364},
           {3,63283554755},
           {53,63291634548}],
          63291634548,
          ok,
          262145024,
          [],
          [],
          0}]

()4> io:format("Person ~r", [P]).
Person #person{pno = 6003310130,
         fname = "Claes",
         lname = "Wikstrom",
         addr = #addr{careof = [],
               street = "Malarhojdsvagen 5a",
               postno = 98765,
               city = "Stockholm",
               telno = [],
               cellno = [],
               email = []},
         post_addr = [],
         extra_company_addrs = [],
         passwd = [],
         estore_names = [{53,"247332"}],
         blacklisted = 0,
         crdata = [{4,63279658768},
          {2,63292552384},
          {5,63280394364},
          {3,63283554755},
          {53,63291634548}],
         crdate = 63291634548,
         crresult = ok,
         credlimit_bits = 262145024,
         letters = [],
         email = [],
         flags = 0}ok




The solution (which I believe has been up for disccussion
earlier here on the list) is pretty expensive, since all
record defs from all modules are kept in an ets table. I'd
say it's worth it though, and if the feature isn't used, the
ets table never gets created.


What do you think ??


/klacke

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: shell.erl.diff
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050907/9529bdc0/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: io_lib_format.erl.diff
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050907/9529bdc0/attachment-0001.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: klacke.vcf
Type: text/x-vcard
Size: 345 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20050907/9529bdc0/attachment.vcf>


More information about the erlang-questions mailing list