[|]
’and []
for lists
Representing lists the conventional way using
as list cell and the atom .
/2'[]'
as list terminator both
(independently) pose conflicts, while these conflicts are easily
avoided.
.
/2
prevents using this commonly
used symbol as an operator because a.B
cannot be
distinguished from [a|B]
. Freeing .
/2
provides us with a unique term that we can use for functional notation
on dicts as described in
section 5.4.1.
'[]'
as list terminator prevents dynamic
distinction between atoms and the empty list. As a result, we cannot use
type polymorphism that involve both atoms and lists. For example, we
cannot use multi lists (arbitrary deeply nested lists) of
atoms. Multi lists of atoms are in some situations a good representation
of a flat list that is assembled from sub sequences. The alternative,
using difference lists or DCGs, is often less natural and sometimes
requires‘opening’proper lists (i.e., copying the list while
replacing the terminating atom '[]'
with a variable) that
have to be added to the sequence. The ambiguity of atom and list is
particularly painful when mapping external data representations that do
not suffer from this ambiguity.
At the same time, avoiding atom '[]'
as a list
terminator makes the various text representations unambiguous, which
allows us to write predicates that require a textual argument to accept
any of atoms, strings, lists of character codes or characters.
Traditionally, the empty list, as an atom, is afflicted with an
ambiguous interpretation as it can stand for any of the strings "[]"
and
""
.