List Syntax

A further form of structuring terms is the list. A list is a short hand for multiple compounds of arity two with the functor ‘.’. A closed list will end in the name ‘[]’. The vertical bar is used to denote open lists ending in the given term.

list         --> "[" arguments [ "|" term(999) ] "]"
| string2. 

[]             % is the empty list, corresponds to '[]'
[a, b]         % is a list, corresponds to .(a, .(b, []))
[X | Y]        % is a list, corresponds to .(X, Y)
"ABC"          % is a list, corresponds to [65, 66, 67]

The double quoted string is a short hand for a list of character codes. The notation is especially useful in connection with definite clause grammars where it then directly denotes a sequence of character terminals.

Instead of a double quoted string also other strings can be used as a short hand, there are Prolog flags that control the default behaviour and there are Prolog options that control the behaviour of the read and write predicates.