简体   繁体   中英

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).

;/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM