Lists

Lists are used to store arbitrary numbers of things. We create a list by enclosing the list elements in square brackets and separating them with commas.

Suppose we want to represent a drawing. If we assume that the drawing is made up of triangles and squares, we could represent the drawing as a list.

 
1>​ Drawing = [{square,{10,10},10}, {triangle,{15,10},{25,10},{30,40}},
 
...​]

Each of the individual elements in the drawing list are fixed-size tuples (for example, {square, Point, Side} or {triangle, Point1, Point2, Point3}), but the drawing itself can contain an arbitrary number of things and so is represented by a list.

The individual elements of a list can be of any type, so, for example, we could write the following:

 
2>​

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.