I want a predicate that goes through a list of lists and checks if each of those lists verify certain conditions, in case a list verifies the conditions, it gets added to ResultList (another list of lists). I wrote this:
mypredicate(ListOfLists, ReferenceList, ResultList) :-
mypredicate(ListOfLists, ReferenceList, ResultList, []),
mypredicate([H|T], ReferenceList, ResultList, Acc) :-
elementos_comuns(ReferenceList, H),
H \== ReferenceList,
append(Acc, H, ResultList),
T \== [],
mypredicate(T, ReferenceList, ResultList, ResultList).
I only want to append if both lines above "append" return true, and regardless of what happens in the first 3 lines, I want it to run the last line if T \== [].
The problem is that when it reaches an element of ListOfLists that doesn't verify one these two:
elementos_comuns(ReferenceList, H),
H \== ReferenceList,
the whole thing returns false.
I need ResultList to be a list of lists that contains the lists from "ListOfList" that verify
elementos_comuns(ReferenceList, H),
H \== ReferenceList,
I have no idea how to do this, any help is appreciated.