Lists are a special class of compound term. They are represented in Prolog as either:
[]
, representing the empty list.
'.'
and two arguments representing
respectively the head and tail of the list. The tail argument must,
itself be a list (possibly empty).
a
,
b
and c
is
represented by the term .(a,.(b,.(c,[])))
. Since this is hard to
read, you can use an alternative notation. Simply write the list as a
sequence of elements separated by commas and enclosed in square
brackets. The previous example could we rewritten using this notation
as [a,b,c]
.
You can confirm this by giving the following goals to Prolog:
| ?- functor(.(a,.(b,.(c,[]))), Functor, Arity). Functor=(.) Arity=2 yes | ?- functor([a,b,c], Functor, Arity). Functor=(.) Arity=2 yes | ?- .(a,.(b,.(c,[]))) = [a,b,c]. yes