**Author(s):** The CLIP Group.

**Version:** 1.10#6 (2004/8/7, 21:46:39 CEST)

**Version of last change:** 1.9#318 (2004/2/26, 15:46:54 CET)

This module provides a set of predicates for list processing.

`lists`

)**Library usage:**`:- use_module(library(lists)).`

**Exports:***Predicates:*`nonsingle/1`

,`append/3`

,`reverse/2`

,`reverse/3`

,`delete/3`

,`delete_non_ground/3`

,`select/3`

,`length/2`

,`nth/3`

,`add_after/4`

,`add_before/4`

,`dlist/3`

,`list_concat/2`

,`list_insert/2`

,`insert_last/3`

,`contains_ro/2`

,`contains1/2`

,`nocontainsx/2`

,`last/2`

,`list_lookup/3`

,`list_lookup/4`

,`intset_insert/3`

,`intset_delete/3`

,`intset_in/2`

,`intset_sequence/3`

,`intersection/3`

,`union/3`

,`difference/3`

,`equal_lists/2`

,`list_to_list_of_lists/2`

,`powerset/2`

,`cross_product/2`

.*Properties:*`list1/2`

,`sublist/2`

,`subordlist/2`

.

`lists`

)- PREDICATE:
**nonsingle/1:** -
**Usage:**`nonsingle(X)`

*Description:*`X`

is not a singleton.

- PREDICATE:
**append/3:** -
**Usage:**`append(Xs, Ys, Zs)`

*Description:*`Zs`

is`Ys`

appended to`Xs`

.

- PREDICATE:
**reverse/2:** -
**Usage:**`reverse(Xs, Ys)`

*Description:*Reverses the order of elements in`Xs`

.*The following properties should hold at call time:*`Xs`

is a list. (`basic_props:list/1`

)`Ys`

is any term. (`basic_props:term/1`

)*The following properties should hold upon exit:*`Xs`

is a list. (`basic_props:list/1`

)`Ys`

is a list. (`basic_props:list/1`

)

- PREDICATE:
**reverse/3:** -
**Usage:**`reverse(A, B, C)`

*Description:*Reverse the order of elements in`A`

, and append it with`B`

.

- PREDICATE:
**delete/3:** -
**Usage:**`delete(L1, E, L2)`

*Description:*`L2`

is`L1`

without the ocurrences of`E`

.

- PREDICATE:
**delete_non_ground/3:** -
**Usage:**`delete_non_ground(L1, E, L2)`

*Description:*`L2`

is`L1`

without the ocurrences of`E`

.`E`

can be a nonground term so that all the elements in`L1`

it unifies with will be deleted

- PREDICATE:
**select/3:** -
**Usage:**`select(X, Xs, Ys)`

*Description:*`Xs`

and`Ys`

have the same elements except for one occurrence of`X`

.

- PREDICATE:
**length/2:** -
**General properties:**`length(A, B)`

*The following properties hold globally:*This predicate is understood natively by CiaoPP. (`basic_props:native/1`

)

**Usage 1:**`length(L, N)`

*Description:*Computes the length of`L`

.*The following properties should hold at call time:*`L`

is a list. (`basic_props:list/1`

)`N`

is a free variable. (`term_typing:var/1`

)*The following properties hold upon exit:*`L`

is a list. (`basic_props:list/1`

)`N`

is an integer. (`basic_props:int/1`

)

**Usage 2:**`length(L, N)`

*Description:*Outputs`L`

of length`N`

.*The following properties should hold at call time:*`L`

is a free variable. (`term_typing:var/1`

)`N`

is an integer. (`basic_props:int/1`

)*The following properties hold upon exit:*`L`

is a list. (`basic_props:list/1`

)`N`

is an integer. (`basic_props:int/1`

)

**Usage 3:**`length(L, N)`

*Description:*Checks that`L`

is of length`N`

.*The following properties should hold at call time:*`L`

is a list. (`basic_props:list/1`

)`N`

is an integer. (`basic_props:int/1`

)*The following properties hold upon exit:*`L`

is a list. (`basic_props:list/1`

)`N`

is an integer. (`basic_props:int/1`

)

- PREDICATE:
**nth/3:** -
`nth(N, List, Elem)`

`N`

is the position in`List`

of`Elem`

.`N`

counts from one.**Usage 1:**`nth(+int, ?list, ?term)`

*Description:*Unifies`Elem`

and the`N`

th element of`List`

.

**Usage 2:**`nth(-int, ?list, ?term)`

*Description:*Finds the positions where`Elem`

is in`List`

. Positions are found in ascending order.

- PREDICATE:
**add_after/4:** -
**Usage:**`add_after(+L0, +E0, +E, -L)`

*Description:*Adds element`E`

after element`E0`

(or at end) to list`L0`

returning in`L`

the new list (uses term comparison).

- PREDICATE:
**add_before/4:** -
**Usage:**`add_before(+L0, +E0, +E, -L)`

*Description:*Adds element E before element E0 (or at start) to list L0 returning in L the new list (uses term comparison).

- PROPERTY:
**list1/2:** -
*Meta-predicate*with arguments:`list1(?,pred(1))`

.**Usage:**`list1(X, Y)`

*Description:*`X`

is a list of`Y`

s of at least one element.

- PREDICATE:
**dlist/3:** -
**Usage:**`dlist(List, DList, Tail)`

*Description:*`List`

is the result of removing`Tail`

from the end of`DList`

(makes a difference list from a list).

- PREDICATE:
**list_concat/2:** -
**Usage:**`list_concat(LL, L)`

*Description:*`L`

is the concatenation of all the lists in`LL`

.*Call and exit should be**compatible*with:`LL`

is a list of`list`

s. (`basic_props:list/2`

)`L`

is a list. (`basic_props:list/1`

)

- PREDICATE:
**list_insert/2:** -
**Usage:**`list_insert(-List, +Term)`

*Description:*Adds`Term`

to the end of`List`

if there is no element in`List`

identical to`Term`

.

- PREDICATE:
**insert_last/3:** -
**Usage:**`insert_last(+L0, +E, -L)`

*Description:*Adds element`E`

at end of list`L0`

returning`L`

.

- PREDICATE:
**contains_ro/2:** -
**Usage:***Description:*Impure membership (does not instantiate a variable in its first argument.

- PREDICATE:
**contains1/2:** -
**Usage:***Description:*First membership.

- PREDICATE:
**nocontainsx/2:** -
**Usage:**`nocontainsx(L, X)`

*Description:*`X`

is not identical to any element of`L`

.

- PREDICATE:
**last/2:** -
**Usage:**`last(L, X)`

*Description:*`X`

is the last element of list`L`

.

- PREDICATE:
**list_lookup/3:** -
**Usage:**`list_lookup(List, Key, Value)`

- PREDICATE:
**list_lookup/4:** -
**Usage:**`list_lookup(List, Functor, Key, Value)`

*Description:*Look up`Functor`

(`Key`

,`Value`

) pair in variable ended key-value pair list`L`

or else add it at the end.

- PREDICATE:
**intset_insert/3:** -
**Usage:**`intset_insert(A, B, Set)`

*Description:*Insert the element`B`

in the ordered set of numbers`A`

.

- PREDICATE:
**intset_delete/3:** -
**Usage:**`intset_delete(A, B, Set)`

*Description:*Delete from the ordered set`A`

the element`B`

.

- PREDICATE:
**intset_in/2:** -
**Usage:**`intset_in(E, Set)`

*Description:*Succeds iff`E`

is element of`Set`

- PREDICATE:
**intset_sequence/3:** -
**Usage:**`intset_sequence(N, L1, L2)`

*Description:*Generates an ordered set of numbers from 0 to`N`

-1, and append it to`L1`

.

- PREDICATE:
**intersection/3:** -
**Usage:**`intersection(+List1, +List2, -List)`

*Description:*`List`

has the elements which are both in`List1`

and`List2`

.

- PREDICATE:
**union/3:** -
**Usage:**`union(+List1, +List2, -List)`

*Description:*`List`

has the elements which are in`List1`

followed by the elements which are in`List2`

but not in`List1`

.

- PREDICATE:
**difference/3:** -
**Usage:**`difference(+List1, +List2, -List)`

*Description:*`List`

has the elements which are in`List1`

but not in`List2`

.

- PROPERTY:
**sublist/2:** -
**Usage:**`sublist(List1, List2)`

*Description:*`List2`

contains all the elements of`List1`

.*If the following properties should hold at call time:*`List2`

is currently a term which is not a free variable. (`term_typing:nonvar/1`

)

- PROPERTY:
**subordlist/2:** -
**Usage:**`subordlist(List1, List2)`

*Description:*`List2`

contains all the elements of`List1`

in the same order.*If the following properties should hold at call time:*`List2`

is currently a term which is not a free variable. (`term_typing:nonvar/1`

)

- PREDICATE:
**equal_lists/2:** -
**Usage:**`equal_lists(+List1, +List2)`

*Description:*`List1`

has all the elements of`List2`

, and vice versa.

- PREDICATE:
**list_to_list_of_lists/2:** -
**Usage:**`list_to_list_of_lists(+List, -LList)`

*Description:*`LList`

is the list of one element lists with elements of`List`

.

- PREDICATE:
**powerset/2:** -
**Usage:**`powerset(+List, -LList)`

*Description:*`LList`

is the powerset of`List`

, i.e., the list of all lists which have elements of`List`

. If`List`

is ordered,`LList`

and all its elements are ordered.

- PREDICATE:
**cross_product/2:** -
**Usage:**`cross_product(+LList, -List)`

*Description:*`List`

is the cartesian product of the lists in`LList`

, that is, the list of lists formed with one element of each list in`LList`

, in the same order.

Go to the first, previous, next, last section, table of contents.