lists, [Head | Tail], .(Head, Tail)
A list in Prolog is written as a comma-separated sequence of items, between square brackets. For example, [1, 2, 3] is a list.

The empty list is written [].

A list with just a single item, say the number 7, is written [7].

Frequently it is convenient to refer to a list by giving the first item, and a list consisting of the rest of the items. In this case, one writes the list as [First | Rest]. Note that Rest must be a list, while Head need not be.

We have expressed this here using variables, but this need not be so, for example, we could write [1, 2, 3] as:

and many more possibilities.

You should always write your Prolog list in the most compact reasonable format. So for example, while [X | []] is the same list as [X], the second version is much easier to read, so you should use it.

It is possible to have lists of lists, or lists some of whose members are themselves lists:

Lists can also be expressed using a normal term syntax, using the built-in predicate name . - that is, a full stop or period. In this case, the empty list atom ([]) must be used to terminate the list. However, this approach is more cumbersome, and in practice people use the [1, 2, 3]- style syntax. Example:

?- X = .(1, .(2, .(3, []))).
X = [1, 2, 3]