Prolog Beginner: How to make unique values for each Variable in a predicate.
- by sixtyfootersdude
I have a prolog predicate:
DoStuff( [A|B] ) :-
<Stuff that I do>
...
</Stuff that I do>
It is all done except it needs to do return unique values. Ie if you do:
?- DoStuff(A,B,C,D).
it should return:
A=1;
B=2;
C=3;
D=4.
(Or something similar, the key point is that all of the values are unique).
However you should be able to do this too:
?- DoStuff(A,A,B,B).
And still get a valid answer. Ie:
A=1;
B=2.
How can I do this? What I was planning on doing was something like this:
DoStuff( [A|B] ) :-
<Stuff that I do>
...
</Stuff that I do>
unique([A|B]).
unique([]).
unique([A|B]) :-
A is not B.
However I think that will make DoStuff([A,A,B]) not work because not all values will be unique.