Tuples
Suppose we want to group a fixed number of items into a single
entity. For this we’d use a tuple. We can
create a tuple by enclosing the values we want to represent in
curly brackets and separating them with commas. So, for example,
if we want to represent someone’s name and height, we might use
{joe, 1.82}. This is a tuple containing an atom and a
floating-point number.
Tuples are similar to structs in C, with the difference that they
are anonymous. In C, a variable P of type point
might be declared as follows:
| | struct point { |
| | int x; |
| | int y; |
| | } P; |
We’d access the fields in a C struct using the dot operator. So,
to set the x and y values in the point, we
might say this:
| | P.x = 10; P.y = 45; |
Erlang has no type declarations, so to ...
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.
Read now
Unlock full access