The definition of this Prolog library Predicate is:
subtract([], _, []). subtract([Head|Tail], L2, L3) :- memberchk(Head, L2), !, subtract(Tail, L2, L3). subtract([Head|Tail1], L2, [Head|Tail3]) :- subtract(Tail1, L2, Tail3).This predicate does not perform any type testing functions.
This predicate works properly for set operations only, so repeated elements and variable elements should not be used.
Success: subtract([1,2,3,4],[1],R). (gives R=[2,3,4]). subtract([1,2,3],[3,4],R). (gives R=[1,2]). subtract([1,1,2,3],[2],[1,1,3]). Fail: subtract([1,1,2,3],[1],[1,2,3]). % Fails - List2 and % Remainder share elements