(1) how to define the delete(X,L1,L2)
relation using Prolog where L2
is the resulted list in which item X
is deleted from list L1
(2) How to draw the derivation tree to answer the following query?
| ?- delete(3,[4,10,6,8,1,3,9],L)
(1) how to define the delete(X,L1,L2)
relation using Prolog where L2
is the resulted list in which item X
is deleted from list L1
(2) How to draw the derivation tree to answer the following query?
| ?- delete(3,[4,10,6,8,1,3,9],L)
Save logical-purity by using the meta-predicate tfilter/3
and reified disequality 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.
Note this works just as fine with non-ground terms, too!
?- 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).