Skip to Content
Introducing Erlang
book

Introducing Erlang

by Simon St. Laurent
January 2013
Beginner to intermediate content levelBeginner to intermediate
204 pages
4h 26m
English
O'Reilly Media, Inc.
Content preview from Introducing Erlang

Chapter 10. Storing Structured Data

Tuples and lists are powerful tools for creating complex data structures, but there are two key pieces missing from the story so far. First, tuples are relatively anonymous structures. Relying on a specific order and number of components in tuples can create major maintenance headaches. Second, despite Erlang’s general preference for avoiding side effects, storing and sharing data is a fundamental side effect needed for a wide variety of projects.

Records will help you create labeled sets of information. Erlang Term Storage (ETS) will help you store and manipulate those sets, and the Mnesia database provides additional features for reliable distributed storage.

From Tuples to Records

Tuples let you build complex data structures, but force you to rely on keeping the order and number of items consistent. If you change the sequence of items in a tuple, or if you want to add an item, you have to check through all of your code to make sure that the change propagates smoothly. As your projects grow, and especially if you need to share data structures with code you don’t control, you’ll need a safer way to store and address information.

Records let you create data structures that use names to connect with data rather than order. You can read, write, and pattern match data in a record without having to worry about the details of where in a tuple a field lurks or whether someone’s added a new field.

Warning

There are still tuples underneath records, and occasionally ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Web Applications with Erlang

Building Web Applications with Erlang

Zachary Kessin
Études for Erlang

Études for Erlang

J. David Eisenberg
Erlang by Example with Cesarini and Thompson

Erlang by Example with Cesarini and Thompson

Simon Thompson, Francesco Cesarini
Erlang and OTP in Action

Erlang and OTP in Action

Eric Merritt, Richard Carlsson, Martin Logan

Publisher Resources

ISBN: 9781449331757Supplemental ContentErrata