¨

10.2.11 Lists

A list is a sequence of terms of the form:

[ t 1 , t 2 ,…, t n ] n ³ 0
The term t i is the i’th element of the list. It can be any type of Prolog term. The simplest form of list is the empty list (n = 0):
[]
The following example is a four element list:
[[a,list,of,lists],and,numbers,[1,2,3]]
Unknown elements of a list can be represented by variables. For example:
[X,Y,Z]
We also represent a list using the notation:
[ t1, t2, …, ti | Variable ] i ³ 1
This list pattern represents a list that begins with the terms t 1 ,t 2 ,…,t i with the remainder of the list (the tail) denoted by Variable.

For example the list pattern:

[Head|Tail]
could be unified with the list:
[1,2,3,4]
to give the variable bindings:
Head = 1
Tail = [2,3,4]