重复的解决方案

Luc*_*cas 8 prolog prolog-setof

我有一个问题,试图获得一些代码,返回我的查询的唯一答案.例如,定义

stuff(A,B,C) :- A=C ; B=C.
morestuff([],[],[]).
morestuff([A|AA],[B|BB],[C|CC]) :- stuff(A,B,C), morestuff(AA,BB,CC).
Run Code Online (Sandbox Code Playgroud)

然后跑

morestuff([A,A],[A,B],[a,b]).
Run Code Online (Sandbox Code Playgroud)

给出输出:

A = a
B = b ? ;

A = a
B = b ? ;

yes.
Run Code Online (Sandbox Code Playgroud)

如您所见,这两种解决方案是相同的.有没有办法让PROLOG回归独特的解决方案,即e.给出输出:

A = a
B = b ? ;

yes.
Run Code Online (Sandbox Code Playgroud)

小智 3

您还可以使用

| ?- setof(sol(A,B),morestuff([A,A],[A,B],[a,b]),L).
L = [sol(a,b)] ? 
yes
Run Code Online (Sandbox Code Playgroud)