Archive for March 9, 2011

Introduction to Erlang : Basic Types (2/2)

This entry is part 5 of 16 in the series Introduction to Erlang

More Data Types

Today we will see some more sophisticated Erlang’s data types; tuple, list, and fun.

Tuple

Tuple is a compound data type; it consists of elements of any data type. A tuple has the form:

{Element1, Element2, ..., ElementN}

where N is called the size the tuple.

1> {1,2}.
{1,2}
2> {true, {value, whatever}}.
{true,{value,whatever}}
3> {1, a, 1.1, {{{{4}}}}}.
{1,a,1.1,{{{{4}}}}}
4> is_tuple({}). % built-in function (BIF)
true
5> element(3, {1,2,3}). % the element at position 3
3
6> size({1,2,3}).% the size of the tuple
3

Read the rest of this entry »