record field names

Mats Cronqvist mats.cronqvist@REDACTED
Fri Sep 16 16:21:41 CEST 2005


   feels like this is an faq, but i can't find it in the archive.

   according to the reference manual:
   "To each module using records, a pseudo function is added during compilation 
to obtain information about records:
record_info(fields, Record) -> [Field]
record_info(size, Record) -> Size"

   now, as i understand it, there is no function, just textual substitution 
(like a macro).

   but why not? if there was a real, exported function record_info/2 (just like 
module_info), one could do a lot of cool things.

  such as turning a record into a tagged tuple;

readable_rec(Module,Rec) ->
   lists:zip(Module:record_info(fields,element(1,Rec)),tl(tuple_to_list(Rec))).

  or write a tool to check that all modules using a certain record agree on its 
definition.

   mats



More information about the erlang-questions mailing list