Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share a record between multiple erl in Erlang?

Tags:

erlang

record

erl

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.

like image 953
TheSquad Avatar asked Feb 22 '12 12:02

TheSquad


People also ask

What is HRL in Erlang?

hrl files are simply erlang "header", that is files containing common definitions that are intended to be included by . erl files.

How do you define an Erlang record?

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.

How do I start Erlang?

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.


1 Answers

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.
like image 67
David Weldon Avatar answered Nov 04 '22 15:11

David Weldon