next up previous contents index
Next: Set Manipulation Up: Built-in predicates Previous: Adding Arithmetic Functions   Contents   Index

List Manipulation

is_list1+Term Succeeds if Term is bound to the empty list ([]) or a term with functor `' and arity 2. proper_list1+Term Equivalent to is_list1, but also requires the tail of the list to be a list (recursively). Examples:
\begin{code}
is_list([x\vert A]) %% true
proper_list([x\vert A]) %% false
\end{code}

append3?List1, ?List2, ?List3 Succeeds when List3 unifies with the concatenation of List1 and List2. The predicate can be used with any instantiation pattern (even three variables). member2?Elem, ?List Succeeds when Elem can be unified with one of the members of List. The predicate can be used with any instantiation pattern. memberchk2?Elem, +List Equivalent to member2, but leaves no choice point. delete3+List1, ?Elem, ?List2 Delete all members of List1 that simultaneously unify with Elem and unify the result with List2. select3?List1, ?Elem, ?List2 Select an element of List1 that unifies with Elem. List2 is unified with the list remaining from List1 after deleting the selected element. Normally used with the instantiation pattern +List1, -Elem, -List2, but can also be used to insert an element in a list using -List1, +Elem, +List2. nth03?Index, ?List, ?Elem Succeeds when the Index-th element of List unifies with Elem. Counting starts at 0. nth13?Index, ?List, ?Elem Succeeds when the Index-th element of List unifies with Elem. Counting starts at 1. last2?Elem, ?List Succeeds if Elem unifies with the last element of List. If List is a proper list last2 is deterministic. If List has an unbound tail, backtracking will cause List to grow. reverse2+List1, -List2 Reverse the order of the elements in List1 and unify the result with the elements of List2. flatten2+List1, -List2 Transform List1, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). Unify the resulting flat list with List2. Example:
\begin{code}
?- flatten([a, [b, [c, d], e]], X).
\par X = [a, b, c, d, e]
\end{code}

length2?List, ?Int Succeeds if Int represents the number of elements of list List. Can be used to create a list holding only variables. merge3+List1, +List2, -List3 List1 and List2 are lists, sorted to the standard order of terms (see compare). List3 will be unified with an ordered list holding both the elements of List1 and List2. Duplicates are not removed.


next up previous contents index
Next: Set Manipulation Up: Built-in predicates Previous: Adding Arithmetic Functions   Contents   Index
Dr. Richard Botting 2001-12-12