I have a prolog predicate:
Add( [A|B] , Answer ) :-
...
~ Add everything in the list to come up with answer
...
I would now lik
Khm... You should understand that doStuff(A,B,C,D)
and doStuff(A,A,B,B)
means. First is going to unify values A
.. D
with appropriate values which makes doStuff/4
reachable goal. And second is equal to A=B, C=D, doStuff(A,B,C,D)
and doStuff(A,B,C,D), A=B, C=D
(but last variant probably will cause backtracking). So I hope you understand that unique/1
shouldn't be done inside doStuff/4
, because it's outside restriction. So you shoulad use doStuff(A,B,C,D), unique([A,B,C,D])
and doStuff(A,A,B,B), unique([A,B])
.
I wonder how you read A is not B
...
Anyway you can define unique/1
as
not_unique([H|T]):- member(H, T) ; not_unique(T).
unique(L):- not(not_unique(L)).