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.
hrl files are simply erlang "header", that is files containing common definitions that are intended to be included by . erl files.
11.1 Defining RecordsA record definition consists of the name of the record, followed by the field names of the record. Record and field names must be atoms. Each field can be given an optional default value. If no default value is supplied, undefined is used.
On a Unix system you enter the command erl at the operating system prompt. This command starts the Erlang runtime system and the Erlang shell. On the Windows platform you normally start Erlang/OTP from the start menu. You can also enter the command erl or werl from a DOS box or Command box.
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").
src
directory unless it's needed outside of your application - in that case you should put it in a directory called include
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With