File "lists"

This module provides persistent lists. Prolog Lists are written as [x1,..,xn] and are internally constructed by the pairing constructor [h|t] and the empty constructor []. The length of such a list is n and the i-th element is xi. Most predicates are implemented such that they leave as few as possible choice points.

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

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

The predicates append/3, reverse/2, member/2, select/3, last/2 and last/3 work directly with lists. The predicates length/2, nth0/3, nth0/4, nth1/3 and nth1/4 take also a length respective index into account. To cater for higher order logic programming with lists, we currently provide the predicates maplist/n which were realized for n = 2..5.

The following list predicates are provided:

memberchk(E, S):
The predicate succeeds once when the list S contains the element E.
last(L, E):
The predicate succeeds with E being the last element of the list L.
last(L, E, R):
The predicate succeeds with E being the last element of the list L and R being the remainder of the list.
nth0(I, L, E):
The predicate succeeds with E being the (I+1)-th element of the list L.
nth0(I, L, E, R):
The predicate succeeds with E being the (I+1)-th element of the list L and R being the remainder of the list.
nth1(I, L, E):
The predicate succeeds with E being the I-th element of the list L.
nth1(I, L, E, R):
The predicate succeeds with E being the I-th element of the list L and R being the remainder of the list.
free_variables(Q, L, G): [ISO 7.1.1.4]
The predicate succeeds in L with the free variabes of Q and in G with the quantifier free of Q.
sort(L, R): [TC2 8.4.3]
The predicate succeeds in R with the unstable sorted list L.
keysort(L, R): [TC2 8.4.4]
The predicate succeeds in R with the stable key sorted list L.
maplist(C, L1, .., Ln): [N235 7.4]
The predicate succeeds whenever the closure C can be applied to each of the joint elements X1, .., Xn in the lists L1, .. Ln.
foldl(C, L1, .., Ln, I, O):
The predicate succeeds in O with the closure C chained through the elements X1, .., Xn of the lists L1, .. Ln starting with I.

Kommentare