Erlang Notes - Records

December 23rd, 2008

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

erlang, programming | Comments | Trackback Jump to the top of this page

Leave a Reply

  •  
  •  
  •  

You can keep track of new comments to this post with the comments feed.

Recently on Flickr

    mull - 21.jpgmull - 20.jpgmull - 19.jpgmull - 18.jpg

Recently Listened

Meta

The Carousell