I'm trying to figure out how to determine if the intersection of two lists is empty in Prolog. From what I understand, this is they have no elements in common. I'm new to Prolog(as of last night). Any help is greatly appreciated.
Here is my attempt:
% returns true if head is not a member of List?
intersection([],_).
intersection([Head|Tail],List) :-
\+ member(Head,List),
intersection(Tail,List).
Second Attempt:
?- intersect([A,B,C,D],[E,F,G,H]).
intersect(L1,L2) :-
intersection(L1,L2,[]).
mbratch's resolution solved the problem.
Solution:
?-intersect([a,b,c,d],[e,f,g,h]).
intersect(L1,L2):-
intersection(L1,L2,[]).