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 3. Atoms, Tuples, and Pattern Matching

Erlang programs are at heart a set of message requests and tools for processing them. Erlang provides tools that simplify the efficient handling of those messages, letting you create code that is readable (to programmers at least) while still running efficiently when you need speed.

Atoms

Atoms are a key structure in Erlang. Technically they’re just another type of data, but it’s hard to overstate their impact on Erlang programming style.

Usually, atoms are bits of text that start with a lowercase letter, like ok or earth. They can also contain (though not start with) underscores (_) and at symbols (@), like this_is_a_short_sentence or me@home. If you want more freedom to start with uppercase letters or use spaces, you can put them in single quotes, like 'Today is a good day'. Generally, the one word lowercase form is easier to read.

Atoms have a value—it’s the same as their text. (Remember, the period after hello isn’t part of the atom—it ends the expression.)

1> hello.
hello

That’s not very exciting in itself. What makes atoms exciting is the way that they can combine with other types and Erlang’s pattern matching techniques to build simple but powerful logical structures.

Pattern Matching with Atoms

Erlang used pattern matching to make the examples in Chapter 2 work, but it was very simple. The name of the function was the one key piece that varied, and as long as you provided a numeric argument Erlang knew what you meant. Erlang’s pattern ...

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