| tests whether a term is member of a list.
member(?Term, ?List)
member/2 declares, that Term is a member of List.
Different cases can be:
- If Term and List are not variables then member/2 tests whether Term is member of List.
By backtracking member/2 succeeds as often as Term is member of List.
- If Term is a variable and List is bound to a list
then member/2 retrieves (by backtracking) all elements of
List and unifies them with Term.
- If Term is not a variable and List is an open list
(i.e. the tail of the list is a variable) then member/2
asserts that Term is a member of List.
Arguments
Term term
List list
Examples
| member(b,[a,b,c]). |
Succeeds.
| | member(X,[a,b]). |
Succeeds twice with substitution
X <- a
X <- b
| | member(a,X).
| Succeeds infinitely with substitution
X <- [a|_1],
X <- [_2,a|_3],
X <- [_4,_5,a|_6],....
| | member(X,Y).
| Succeeds infinitely with substitution
X <- _1, Y <- [_1|_2],
X <- _3, Y <- [_4,_3|_5],
X <- _6, Y <- [_7,_8,_6|_9], ...
|
Standard
This predicate is not part of the ISO-Prolog Standard.
See also
append/3,
reverse/2/3,
sort/2.
merge_sort/2.
|