(1)如何使用Prolog定义delete(X,L1,L2)
关系,其中L2
是从列表X
中删除项L1
的结果列表
(2)如何绘制派生树以回答以下查询?
| ?- delete(3,[4,10,6,8,1,3,9],L)
答案 0 :(得分:3)
使用logical-purity meta-predicate保存tfilter/3
并确认dif/3
:
?- tfilter(dif(3),[ 4, 10,6,8,1,3,9],[4,10,6,8,1,9]).
true.
?- tfilter(dif(3),[3,3,3,4,3,3,10,6,8,1,3,9],[4,10,6,8,1,9]).
true.
请注意,这也适用于非基础术语!
?- tfilter(dif(Y),[A,B],Xs).
Xs = [ ], Y = A, A = B ;
Xs = [ B], Y = A, dif(A,B) ;
Xs = [A ], Y = B, dif(B,A) ;
Xs = [A,B], dif(Y,B), dif(Y,A).