The Full Wiki

More info on Erlang Programming/Records

Erlang Programming/Records: Wikis

Advertisements

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Wikibooks

Up to date as of January 23, 2010

From Wikibooks, the open-content textbooks collection

< Erlang Programming

Records in Erlang are syntactic sugar for tagged tuples. The functionality is provided by the preprocessor, not the compiler, so there are some interesting restrictions on how you use them and their support functions.

Defining Records

-define(myrecord, {first_element, second_element}).

The code above defines a record called myrecord with two elements: "first_element" and "second_element". From now on we can use the record syntax #myrecord{}.

Equivalent to Tuples

Records are syntactic sugar for tuples.

#myrecord{first_element=foo, second_element=bar} =:= {myrecord, foo, bar}.
#myrecord{} =:= {myrecord, undefined, undefined}.

The record we defined with two fields is equivalent to a tuple with a tag (the name of the record) and as many elements as the record has fields -- two, in our case.


Advertisements






Got something to say? Make a comment.
Your name
Your email address
Message