Lists in Prolog

Lists are sequences of items of unlimited (in theory) length.

A list in Prolog looks like:

[1,2,3,4,5]

[a,b,c,d,e]

[1,a,f(b),[2,c,g(d,e)],5]

A list can contain totally different elements: numbers, symbols, compound terms and sublists.

Due to its internal structure, lists are in fact terms of the form list(head,tail), where head is a single element while tail is a list of the other remaining elements of the original list. Hence any list can be unified with:

[H|T]

where H will be unified with head and T with tail of the list. For example:

[H|T]=[a,b,c,d,e]

will lead to H=a and T=[b,c,d,e]. Remember that the tail of a list is always a list itself!

An empty list is denoted as [].

A list can be used to represent:

Depending on the current interpretation an appropriate processing algorithms are necessary.

For more details see: Lists in Prolog.

For some specific predicates see: SWI-Prolog and go to: 4.28 Built-in list operations and A.11 library( lists ): List Manipulation.