为什么这两个prolog代码会给出不同的结果?

时间:2018-04-30 12:53:05

标签: prolog

call((append(As,Bs,[1,2,3,4]),writeq(user,append(As,Bs,[1,2,3,4])))).

结果:

append([],[1,2,3,4],[1,2,3,4])
As = [],
Bs = [1,2,3,4] ? ;
append([1],[2,3,4],[1,2,3,4])
As = [1],
Bs = [2,3,4] ? ;
append([1,2],[3,4],[1,2,3,4])
As = [1,2],
Bs = [3,4] ? ;
append([1,2,3],[4],[1,2,3,4])
As = [1,2,3],
Bs = [4] ? ;
append([1,2,3,4],[],[1,2,3,4])
As = [1,2,3,4],
Bs = [] ? ;
no

但如果我试试这个:

 call((append(As,Bs,[1,2,3,4]) -> writeq(append(As,Bs,[1,2,3,4])) ; writeq('There are no solutions.\n'))).

它回馈了这个:

append([],[1,2,3,4],[1,2,3,4])
As = [],
Bs = [1,2,3,4] ? ;
no

有什么区别?我尝试写它,以便它可以判断是否有0个解决方案。

0 个答案:

没有答案
相关问题