I am writing a prolog code and in the middle i want to check is all the elements in a list are a not included in a certain predicate
Here is the code:
trap(a).
trap(b).
not_trap([A|B]):-
\+trap(A),
not_trap(B).
not_trap(B):-
\+trap(B).
but this wont work can anyone tell me where I went wrong?
Thanks
Your base case is wrong. Whatever list you give to this predicate will be classified as not containing a trap, since the second clause matches it:
You can fix this predicate by either using the typical list recursion base case of
or by rewriting it without explicit recursion as
(Read this as: there is no member
XofLthat is a trap.)