Naming Tuple Items with Records

In a small tuple, remembering what the individual elements represent is rarely a problem, but when there are a large number of elements in the tuple, it becomes convenient to name the individual elements. Once we have named the elements, we will be able to refer to them using the name and not have to remember what position they had in the tuple.

To name the elements in a tuple, we use a record declaration that has the following syntax:

 
-record​(Name, {
 
%% the next two keys have default values
 
key1 = Default1,
 
key2 = Default2,
 
...
 
%% The next line is equivalent to
 
%% key3 = undefined
 
key3,
 
...
 
}).

Warning: record is not a shell command (use rr in the shell; see the description that ...

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.