Erlang Notes – Records

Here is the eighth of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.

Records

Records are a way of providing a names for elements of tuples.

Record declarations are created in .hrl files with a syntax like:


-record(events, {day=monday,name=hangover}).

This gives us the ability to create a new event record with attributes of day and name. Like this:


X1 = #event{day=monday,name=hangover}).

Remember, its really just a tuple, but because we make it a record, it gets to have names for its variables. We can pattern match to get the variables out of the record. To get the values out of X1 above for example:


#event{day=D,name=N} = X1.
D.
monday

Leave a Comment