Steven
Steven

Reputation: 81

prolog check element existence in list

for the question "how to check if the 3 is member of a list" I defined the follow predicate

member(E,[E|_]).
member(E,[_|R] :- member(E,R).

isthreeinlist(L) :- member(3,L).

but how to "check whether 3 OR 4 is member of a list"?

any hint?

(3 AND 4 is easy though).

Upvotes: 0

Views: 7756

Answers (1)

whd
whd

Reputation: 1861

;/2

is or predicate in prolog, check for description here

for example

threeorfor(X):- member(3,X); member(4,X).
    threeorfor([1,2,5]).
false

threeorfor([1,2,3]).
true
false
threeorfor([1,2,4]).
true

Upvotes: 1

Related Questions