[erlang-questions] Why are records not 'export'-able?
Fri Jun 29 18:08:56 CEST 2012
Sadly, I *knew* that records don't survive compilation - just didn't put the pieces together.
-include_lib is pretty much the most logical option here. The only question remaining is "How much refactoring do I want to do?" :-)
That Tall Bald Indian Guy...
Blog | Twitter | Google+
On Jun 29, 2012, at 11:27 AM, Robert Virding wrote:
> 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.
> 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".
> Mahesh Paolini-Subramanya
> That Tall Bald Indian Guy...
> Blog | Twitter | Google+
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions