projog

3.122. subtract(X,Y,Z) - removes elements from a list.

subtract(X,Y,Z) removes the elements in the list represented by Y from the list represented by X and attempts to unify the result with Z.

Examples

?- subtract([a,b,c,d,e,f], [a,s,d,f], [b,c,e]).

yes

?- subtract([a,b,a,a,d,c,d,e,f], [a,s,d,f], [b,c,e]).

yes

?- subtract([a,b,a,a,d,c,d,e,f], [], [a,b,a,a,d,c,d,e,f]).

yes

?- subtract([], [a,s,d,f], []).

yes

?- subtract([], [], []).

yes

?- subtract([a,a,a,a], [X], Z).
X = a
Z = []

yes

?- subtract([a,a,a,a,b], [X], Z).
X = a
Z = [b]

yes

?- subtract([p(A),p(B),p(C)], [p(a)],Z).
A = a
B = a
C = a
Z = []

yes

?- subtract([p(a,B,c,e)], [p(A,b,C,e)], Z).
A = a
B = b
C = c
Z = []

yes

?- subtract([p(a,B,c,x)], [p(A,b,C,e)], Z).
A = UNINSTANTIATED VARIABLE
B = UNINSTANTIATED VARIABLE
C = UNINSTANTIATED VARIABLE
Z = [p(a, B, c, x)]

yes

?- subtract([p(a,B), p(A,b)], [p(A,B)], Z).
A = a
B = b
Z = []

yes

?- subtract(X, [], []).

no

?- subtract([], X, []).

no

?- subtract(X, Y, []).

no