Question

I would like to use a -record in every single erl files I have. I know I can repeat the record individually in every files, but that's really ugly.

Any suggestion ?

P.S. : Be gentle ;-) I'm an Erlang newbie.

Was it helpful?

Solution

Put your record definition in a header (.hrl) file. For example, animal.hrl may look like:

-record(animal, {name, legs=4, eyes=2}).

Then in your .erl files you can include the .hrl file like so:

-include_lib("animal.hrl").
  • I'd recommend reading this.
  • Note that the .hrl file should probably be placed in your src directory unless it's needed outside of your application - in that case you should put it in a directory called include.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top