11.3.118 member/2

Synopsis

member(?Element, ?List)

is true if Element occurs in the List. It may be used to test for an element or to enumerate all the elements by backtracking. Indeed, it may be used to generate the List!

Arguments

Element
term
List
list of term

Description

In the context of this predicate, a term occurs in a list if it can be unified with an element of the list.

Backtracking

On backtracking, an attempt is made to unify Element with successive elements of List. If List is not a proper list, then on backtracking it is unified with lists of ever increasing length.

Examples

     
     | ?- member(foo(X), [foo(1), bar(2), foo(3)]).
     X = 1 ? ;
     X = 3 ? ;
     no

See Also

ref-lte-acl, library(lists).


Send feedback on this subject.