Select from two lists at the same position. True if `XList` is
unifiable with `YList` apart a single element at the same
position that is unified with `X` in `XList` and with `Y`
in `YList`. A typical use for this predicate is to *replace*
an element, as shown in the example below. All possible substitutions
are performed on backtracking.
?- select(b, [a,b,c,b], 2, X).
X = [a, 2, c, b] ;
X = [a, b, c, 2] ;
false.

- See also
- selectchk/4 provides a
semidet version.

Select/insert element at index. True when `Elem` is the `N`’th
(0-based) element of `List` and `Rest` is the
remainder (as in by
select/3) of `List`.
For example:
?- nth0(I, [a,b,c], E, R).
I = 0, E = a, R = [b, c] ;
I = 1, E = b, R = [a, c] ;
I = 2, E = c, R = [a, b] ;
false.

?- nth0(1, L, a1, [a,b]).
L = [a, a1, b].

True when `Length` is the number of elements in the proper list
`List`. This is equivalent to
proper_length(List, Length) :-
is_list(List),
length(List, Length).

True when `Xs` is a permutation of `Ys`. This can
solve for `Ys` given
`Xs` or `Xs` given `Ys`, or even enumerate `Xs`
and `Ys` together. The predicate permutation/2
is primarily intended to generate permutations. Note that a list of
length N has N! permutations, and unbounded permutation generation
becomes prohibitively expensive, even for rather short lists (10! =
3,628,800).
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 illustrates 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.

- Errors
`type_error(list, Arg)`

if either argument is not a proper or
partial list.

Is true if `FlatList` is a non-nested version of `NestedList`.
Note that empty lists are removed. In standard Prolog, this implies that
the atom’`[]`

’is removed too. In SWI7, `[]`

is distinct from’`[]`

’.
Ending up needing flatten/2
often indicates, like append/3
for appending two lists, a bad design. Efficient code that generates
lists from generated small lists must use difference lists, often
possible through grammar rules for optimal readability.

- See also
- append/2

`Pairs` is a list of `Item-Count`

pairs that
represents the *run length encoding* of `Items`. For
example:
?- clumped([a,a,b,a,a,a,a,c,c,c], R).
R = [a-2, b-1, a-4, c-3].

- Compatibility
- SICStus

True when `Max` is the largest member according to `Pred`,
which must be a 2-argument callable that behaves like (`@=<`

)/2.
Fails if `List` is empty. The following call is equivalent to max_member/2:
?- max_member(@=<, X, [6,1,8,4]).
X = 8.

- See also
- max_list/2 for the
maximum of a list of numbers.

True when `Min` is the smallest member according to `Pred`,
which must be a 2-argument callable that behaves like (`@=<`

)/2.
Fails if `List` is empty. The following call is equivalent to max_member/2:
?- min_member(@=<, X, [6,1,8,4]).
X = 1.

- See also
- min_list/2 for the
minimum of a list of numbers.