5.1.1 Motivating
'[|]
' and []
for lists
Representing lists the conventional way using
as cons-cell and '[]' as list terminator both (independently) poses
conflicts, while these conflicts are easily avoided.
.
/2
- Using
prevents using this commonly used symbol as an operator because.
/2a.B
cannot be distinguished from[a|B]
. Freeing
provides us with a unique term that we can use for functional notation on dicts as described in section 5.4.1..
/2 - Using
'[]'
as list terminator prevents dynamic distinction between atoms and lists. 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 demands for `opening' proper lists (i.e., copying the list while replacing the terminating empty list 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
'[]'
as a list terminator makes the various text representations unambiguous, which allows us to write predicates that require a textual argument to accept both atoms, strings, and lists of character codes or one-character atoms. Traditionally, the empty list can be interpreted both as the string "[]" and "".