This library provides commonly accepted basic predicates for list manipulation in the Prolog community. Some additional list manipulations are built-in. See e.g., memberchk/2, length/2.
The implementation of this library is copied from many places. These include: "The Craft of Prolog", the DEC-10 Prolog library (LISTRO.PL) and the YAP lists library.
member(X, [One]).
| ListOfLists | must be a list of -possibly- partial lists |
?- select(b, [a,b,c], 2, X). X = [a, 2, c] ; X = [a, b, c].
==), delete first/all, be deterministic or
not.
If both Xs and Ys are provided and both lists
have equal length the order is |Xs|^2.
Simply testing whether Xs is a permutation of Ys
can be achieved in order log(|Xs|)
using msort/2 as
illustrated below with the semidet predicate is_permutation/2:
is_permutation(Xs, Ys) :- msort(Xs, Sorted), msort(Ys, Sorted).
The example below illustrate that Xs and Ys being proper lists is not a sufficient condition to use the above replacement.
?- permutation([1,2], [X,Y]). X = 1, Y = 2 ; X = 2, Y = 1 ; false.
|List|^2.
|Set1|*|Set2|
|Set1|*|Set2|
|SubSet|*|Set|.
|Delete|*|Set|.