Erlang provides the following data types1 which are called terms:

  • Constant data types
    • Numbers ∗ Integers, for storing natural numbers ∗ Floats, for storing real numbers
    • Atoms
    • Pids (short for process identifiers), for storing process names
    • References, for storing system unique references
  • Compound data types
    • Tuples, for storing a fixed number of terms
    • Lists, for storing a variable number of terms

2.1.1. Numbers

Numbers are written as in the following examples:

123 -34567 12.345 -27.45e-05

The precision of integers is a local issue but at least 24-bit integer precision must be provided by any Erlang system.

The notation $<Char> represents the ASCII value of the character Char so, for example, $A represents the integer 65.

Integers with base other than 10 are written using the notation <Base>#<Value> so, for example, 16#ffff represents the integer 65535 (in base 10). The value of Base must be an integer in the range 2..16.

Floating point numbers are written in conventional notation.

2.1.2. Atoms

Atoms are constants with names; thus, for example, the atoms monday, tuesday, ... could be used to represent days of the week in some program which performs calendar calculations. Atoms are used to enhance the legibility of programs.

Examples of atoms:

friday unquoted_atoms_cannot_contain_blanks
'A quoted atom which contains several blanks'
'hello \n my friend'

Atoms begin with a lower-case letter (a..z) and are terminated by a non- alphanumeric character – otherwise they must be quoted.

By enclosing the atom name in single quotes any character may be included within the atom. Atoms will always be printed in such a manner that they can be read back by the Erlang reader. Within a quoted atom the following conventions apply:

Characters Meaning
\b backspace
\d delete
\e escape
\f form feed
\n newline
\r carriage return
\t tab
\v vertical tab
\\ backslash
\^A .. \^Z control A to control Z (i.e. 0 .. 26)
\' single quote
\" double quote
\000 The character with octal representation OOO

If a quoted atom contains the sequence \C, where the ASCII value of C is < 32, then the character codes representing \C are omitted from the atom (this allows long atoms to be split over several lines by terminating each line with a backslash followed by new line).

2.1.3. Tuples

Terms separated by commas and enclosed in curly brackets are called tuples. Tuples are used for storing a fixed number of items. They are similar to structures or records in conventional programming languages.

The tuple {E1,E2,...,En}, where n ≥ 0, is said to have size n. The individual terms occurring in the tuple are referred to as elements.

Examples of tuples:

{a, 12, ’hello’}
{1, 2, {3, 4}, {a, {b, c}}}
{}

2.1.4. Lists

Terms separated by commas and enclosed in square brackets are called lists. Lists are used for storing a variable number of items.

The list [E1,E2,...,En], where n ≥ 0, is said to have length n. Examples of lists:

[1, abc, [12], ’foo bar’]
[]
[a,b,c]
"abcd"

The notation "...", which we call a string, is shorthand for the ASCII representation of the list of characters occurring within the quotes. Thus "abc" denotes the list [97,98,99]. Within a string the quoting conventions used within an atom also apply.

When processing lists it is often convenient to be able to refer to the first element of the list and the remainder of the list when the first element has been removed. By convention, we refer to the first element of the list as the head of the list and the remainder of the list as the tail.

The notation [E1,E2,E3,...,En|Variable], where n ≥ 1, is used to denote a list whose first n elements are E1,E2,E3,...,En and whose remainder is the object denoted by Variable.

Note that the term following the | need not be a list but can be any valid Erlang term. Lists whose last tail is the term [] are called proper or well-formed lists – most (though not all) Erlang programs are written to manipulate well-formed lists.