[erlang-questions] Why are records not 'export'-able?

Robert Virding robert.virding@REDACTED
Fri Jun 29 17:27:10 CEST 2012

The main reason is that records are purely compile-time and record definitions only exist in the compiler. At runtime a record is just a normal tuple with nothing in it to show that it came from a record or what the record definition is. So there are no problems accessing record as tuples and tuples as records, though in most cases it is a stupid thing to do. 

So the problem is that you need to be able to access the record definition whenever a module using it is compiled. One solution is to put the record definition .hrl file in an applications include directory. It is then possible to access that file from the compiler using: 


The compiler will extend the app name with version numbers when necessary. 


----- Original Message -----

> If I have a record I use in just one module, I declare it in that
> module.
> If I have a record I use across a number of modules, I declare it in
> an included file.
> If I have a record that I use across a number of applications, I end
> up declaring it once in each application.

> The simple-minded me says "Hmf. If I could just have a
> '-export_record' declaration, then I could do some fun things like
> '-record(Name, Application:Record)'

> The more realistic me says "There is probably some reason why you
> can't do this. Probably has to do with compilers. It usually does".

> Anyone?

> Mahesh Paolini-Subramanya
> That Tall Bald Indian Guy...
> Blog | Twitter | Google+

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120629/f8da0bea/attachment.htm>

More information about the erlang-questions mailing list