From 5c54ff89a192d9b4908174fadaffcce833fbb58b Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 3 Jan 2011 21:55:42 -0600 Subject: [PATCH] add subtract/3 to lists. --- docs/yap.tex | 14 +++++++++++++- library/lists.yap | 31 +++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/yap.tex b/docs/yap.tex index 6e09202af..8f3e92ff3 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -1,4 +1,4 @@ -�a\input texinfo @c -*- mode: texinfo; coding: latin-1; -*- +\input texinfo @c -*- mode: texinfo; coding: latin-1; -*- @c %**start of header @setfilename yap.info @@ -9242,6 +9242,18 @@ Succeeds if @var{Set3} unifies with the intersection of @var{Set1} and need not be ordered. @end table +@item subtract(+@var{Set}, +@var{Delete}, ?@var{Result}) +@findex subtract/3 +@syindex subtract/3 +@cnindex subtract/3 +Delete all elements from @var{Set} that occur in @var{Delete} (a set) +and unify the result with @var{Result}. Deletion is based on +unification using @code{memberchk/2}. The complexity is +@code{|Delete|*|Set|}. + +See @code{ord_subtract/3}. +@end table + @node LineUtilities, MapList, Lists, Library @section Line Manipulation Utilities @cindex Line Utilities Library diff --git a/library/lists.yap b/library/lists.yap index fa84c4e53..c907b9144 100644 --- a/library/lists.yap +++ b/library/lists.yap @@ -8,9 +8,14 @@ append/3, append/2, delete/3, + intersection/3, + flatten/2, last/2, + list_concat/2, + max_list/2, member/2, memberchk/2, + min_list/2, nextto/3, nth/3, nth/4, @@ -18,6 +23,7 @@ nth0/4, nth1/3, nth1/4, + numlist/3, permutation/2, prefix/2, remove_duplicates/2, @@ -27,16 +33,11 @@ selectchk/3, sublist/2, substitute/4, + subtract/3, + suffix/2, sum_list/2, sum_list/3, - suffix/2, - sumlist/2, - list_concat/2, - flatten/2, - max_list/2, - min_list/2, - numlist/3, - intersection/3 + sumlist/2 ]). :- use_module(library(error), @@ -400,3 +401,17 @@ intersection([X|T], L, Intersect) :- intersection([_|T], L, R) :- intersection(T, L, R). +%% subtract(+Set, +Delete, -Result) is det. +% +% Delete all elements from `Set' that occur in `Delete' (a set) +% and unify the result with `Result'. Deletion is based on +% unification using memberchk/2. The complexity is |Delete|*|Set|. +% +% @see ord_subtract/3. + +subtract([], _, []) :- !. +subtract([E|T], D, R) :- + memberchk(E, D), !, + subtract(T, D, R). +subtract([H|T], D, [H|R]) :- + subtract(T, D, R).