I'm trying to write a predicate common(L, S) which from a list of lists L generates in S all common subsequences of the lists in L.
subseq([], _).
subseq([H|S], L) :- append(_, [H|T], L), subseq(S, T).
common(L, X) :- not((
member(A, L),
not(subseq(X, A))
)).
It just gives me 'true' even with wrong input.
For example:
common([[1,2,3,4], [2,3], [12]], X).
true
Edit
I've noticed that it's actually working but it's just not substituting X with the term for which the predicate is true.
'yes'
? Can you give the exact query? Furthermore that is logical: negation in Prolog is not constructive. So it will either return true or false. – Willem Van Onsemsubseq([], _). subseq([H|S], L) :- append(_, [H|T], L), subseq(S, T).
It still behaves the same way. I've noticed that it's working properly when I give it exact values, but when trying to substitute X with the result it doesn't work. It just gives 'yes' – Nikola