I am trying to write a function that takes in two lists and returns true if every element in the first list appears at least once in the second list. Example:
allMember(X, [a,b]).
X = [] ;
X = [a] ;
X = [b] ;
X = [a a] ;
X = [a b] ;
X = [b a] ;
X = [b b] ;
false.
The trouble is that after the final ; the program loops infinitely checking every possible list. How can I fix this?
allmember([], _).
allmember([F|R], L2) :- length([F|R], Len1),
length(L2, Len2),
Len1 =< Len2,
member(F, L2),
allmember(R, L2).