Data Structures
Erlang has eight primitive data types:
- Integers: integers are written as sequences of decimal digits, for example, 12, 12375 and -23427 are integers. Integer arithmetic is exact and only limited by available memory on the machine. (This is called arbitrary-precision arithmetic.)
- Atoms: atoms are used within a program to denote distinguished values. They are written as strings of consecutive alphanumeric characters, the first character being a small letter. Atoms can contain any character if they are enclosed within single quotes and an escape convention exists which allows any character to be used within an atom.
- Floats: floating point numbers use the IEEE 754 64-bit representation. (Range: ±10308.)
- References: references are globally unique symbols whose only property is that they can be compared for equality. They are created by evaluating the Erlang primitive
make_ref
. - Binaries: a binary is a sequence of bytes. Binaries provide a space-efficient way of storing binary data. Erlang primitives exist for composing and decomposing binaries and for efficient input/output of binaries.
- Pids: Pid is short for process identifier—a Pid is created by the Erlang primitive
spawn(...)
Pids are references to Erlang processes. - Ports: ports are used to communicate with the external world. Ports are created with the built-in function (BIF)
open_port
. Messages can be sent to and received from ports, but these messages must obey the so-called "port protocol." - Funs : Funs are function closures. Funs are created by expressions of the form:
fun(...) -> ... end
.
And two compound data types:
- Tuples : tuples are containers for a fixed number of Erlang data types. The syntax
{D1,D2,...,Dn}
denotes a tuple whose arguments areD1, D2, ... Dn.
The arguments can be primitive data types or compound data types. The elements of a tuple can be accessed in constant time. - Lists : lists are containers for a variable number of Erlang data types. The syntax
denotes a list whose first element is
Dh
, and whose remaining elements are the listDt
. The syntaxdenotes an empty list. The syntax
is short for
]]]
. The first element of a list can be accessed in constant time. The first element of a list is called the head of the list. The remainder of a list when its head has been removed is called the tail of the list.
Two forms of syntactic sugar are provided:
- Strings : strings are written as doubly quoted lists of characters, this is syntactic sugar for a list of the integer ASCII codes for the characters in the string, thus for example, the string "cat" is shorthand for
. It has partial support for unicode strings
- Records : records provide a convenient way for associating a tag with each of the elements in a tuple. This allows us to refer to an element of a tuple by name and not by position. A pre-compiler takes the record definition and replaces it with the appropriate tuple reference.
Erlang has no method of defining classes, although there are external libraries available.
Read more about this topic: Erlang (programming Language)
Famous quotes containing the words data and/or structures:
“This city is neither a jungle nor the moon.... In long shot: a cosmic smudge, a conglomerate of bleeding energies. Close up, it is a fairly legible printed circuit, a transistorized labyrinth of beastly tracks, a data bank for asthmatic voice-prints.”
—Susan Sontag (b. 1933)
“The philosopher believes that the value of his philosophy lies in its totality, in its structure: posterity discovers it in the stones with which he built and with which other structures are subsequently built that are frequently betterand so, in the fact that that structure can be demolished and yet still possess value as material.”
—Friedrich Nietzsche (18441900)