[ library(lists) | The ECLiPSe Libraries | Reference Manual | Alphabetic Index ]

memberchk(+Term, ?List)

Succeeds if Term is a member of the list List.
+Term
Prolog term.
?List
List or a variable.

Description

Unifies Term with the first matching element of the list List.

If List is not instantiated, memberchk/2 binds List to a new partial list containing an element Term.

The definition of this Prolog library predicate is:

memberchk(X,[X|_]) :- !.
memberchk(X,[_|T]):- memberchk(X,T).
This predicate does not perform any type testing functions.

Modes and Determinism

Fail Conditions

Fails if Term is not a member of the list List.

Resatisfiable

No.

Examples

Success:
      memberchk(0,[1,B,2]). (gives B=0).
      memberchk(1,[1,X]).   (gives X=_g76).
      memberchk(1,X), memberchk(2,X).
                            (gives X=[1,2|_g98]).

Fail:
      memberchk(0,[1,2,3,4]).



See Also

member / 2