Search code examples
erlangrecords

Listing available records available to a process in Erlang


Records are compile time structures. The record_info and is_record recognise the compiled records and their structures. Is there a way to ask the VM what records have been defined that are available to the process? I am interested in getting the internal tuple representation for every record definition.

What I want to do is something like:

-record(car,{make=honda}).

get_record(Car) -> %% Some magic here to end up having sth like {car,{make,honda}} or even better #car{} indeed. %% when Car = 'car'


Solution

  • I have used Dynarec (https://github.com/dieswaytoofast/dynarec.git) successfully in a data mapping module for one of the apps I am currently working on. It is a parse transformer, though, not a run-time VM tool. It compiles information on each defined record, as well as information about the fields for each record. In my case, I use it to dynamically map incoming data to record data. This module may get you what you need. YMMV. Good luck.