5.1 Lists are special

As of version 7, SWI-Prolog lists can be distinguished unambiguously at runtime from ./2 terms and the atom '[]'. The constant [] is special constant that is not an atom. It has the following properties:

?- atom([]).
false.
?- atomic([]).
true.
?- [] == '[]'.
false.
?- [] == [].
true.

The `cons' operator for creating list cells has changed from the pretty atom '.' to the ugly atom '[|]', so we can use the '.' for other purposes. See section 5.4.1.

This modification has minimal impact on typical Prolog code. It does affect foreign code (see section 10) that uses the normal atom and compound term interface for manipulation lists. In most cases this can be avoided by using the dedicated list functions. For convenience, the macros ATOM_nil and ATOM_dot are provided by SWI-Prolog.h.

Another place that is affected is write_canonical/1. Impact is minimized by using the list syntax for lists. The predicates read_term/2 and write_term/2 support the option dot_lists(true), which causes read_term/2 to read .(a,[]) as [a] and write_term/2 to write [a] as .(a,[]).

5.1.1 Motivating ' ' and[]for lists

Representing lists the conventional way using ./2 as cons-cell and '[]' as list terminator both (independently) poses conflicts, while these conflicts are easily avoided.