eqv? is used to test for membership by procedures which treat
lists as sets.
adjoinreturns the adjoint of the element e and the list l. That is, if e is in l,adjoinreturns l, otherwise, it returns(conse l).Example:
(adjoin 'baz '(bar baz bang)) ⇒ (bar baz bang) (adjoin 'foo '(bar baz bang)) ⇒ (foo bar baz bang)
unionreturns a list of all elements that are in l1 or l2. Duplicates between l1 and l2 are culled. Duplicates within l1 or within l2 may or may not be removed.Example:
(union '(1 2 3 4) '(5 6 7 8)) ⇒ (1 2 3 4 5 6 7 8) (union '(0 1 2 3 4) '(3 4 5 6)) ⇒ (5 6 0 1 2 3 4)
intersectionreturns a list of all elements that are in both l1 and l2.Example:
(intersection '(1 2 3 4) '(3 4 5 6)) ⇒ (3 4) (intersection '(1 2 3 4) '(5 6 7 8)) ⇒ ()
set-differencereturns a list of all elements that are in l1 but not in l2.Example:
(set-difference '(1 2 3 4) '(3 4 5 6)) ⇒ (1 2) (set-difference '(1 2 3 4) '(1 2 3 4 5 6)) ⇒ ()
Returns
#tif every element of list1 iseqv?an element of list2; otherwise returns#f.Example:
(subset? '(1 2 3 4) '(3 4 5 6)) ⇒ #f (subset? '(1 2 3 4) '(6 5 4 3 2 1 0)) ⇒ #t
member-ifreturns the list headed by the first element of lst to satisfy(pred element).Member-ifreturns#fif pred returns#ffor every element in lst.Example:
(member-if vector? '(a 2 b 4)) ⇒ #f (member-if number? '(a 2 b 4)) ⇒ (2 b 4)
pred is a boolean function of as many arguments as there are list arguments to
somei.e., lst plus any optional arguments. pred is applied to successive elements of the list arguments in order.somereturns#tas soon as one of these applications returns#t, and is#fif none returns#t. All the lists should have the same length.Example:
(some odd? '(1 2 3 4)) ⇒ #t (some odd? '(2 4 6 8)) ⇒ #f (some > '(1 3) '(2 4)) ⇒ #f
everyis analogous tosomeexcept it returns#tif every application of pred is#tand#fotherwise.Example:
(every even? '(1 2 3 4)) ⇒ #f (every even? '(2 4 6 8)) ⇒ #t (every > '(2 3) '(1 4)) ⇒ #f
notanyis analogous tosomebut returns#tif no application of pred returns#tor#fas soon as any one does.
noteveryis analogous tosomebut returns#tas soon as an application of pred returns#f, and#fotherwise.Example:
(notevery even? '(1 2 3 4)) ⇒ #t (notevery even? '(2 4 6 8)) ⇒ #f
Returns a predicate which returns true if its argument is a list every element of which satisfies predicate. — Function: list-of?? predicate low-bound high-bound
low-bound and high-bound are non-negative integers.
list-of??returns a predicate which returns true if its argument is a list of length between low-bound and high-bound (inclusive); every element of which satisfies predicate. — Function: list-of?? predicate bound
bound is an integer. If bound is negative,
list-of??returns a predicate which returns true if its argument is a list of length greater than(-bound); every element of which satisfies predicate. Otherwise,list-of??returns a predicate which returns true if its argument is a list of length less than or equal to bound; every element of which satisfies predicate.
find-ifsearches for the first element in lst such that(pred element)returns#t. If it finds any such element in lst, element is returned. Otherwise,#fis returned.Example:
(find-if number? '(foo 1 bar 2)) ⇒ 1 (find-if number? '(foo bar baz bang)) ⇒ #f (find-if symbol? '(1 2 foo bar)) ⇒ foo
removeremoves all occurrences of elt from lst usingeqv?to test for equality and returns everything that's left. N.B.: other implementations (Chez, Scheme->C and T, at least) useequal?as the equality test.Example:
(remove 1 '(1 2 1 3 1 4 1 5)) ⇒ (2 3 4 5) (remove 'foo '(bar baz bang)) ⇒ (bar baz bang)
remove-ifremoves all elements from lst where(pred element)is#tand returns everything that's left.Example:
(remove-if number? '(1 2 3 4)) ⇒ () (remove-if even? '(1 2 3 4 5 6 7 8)) ⇒ (1 3 5 7)
remove-if-notremoves all elements from lst for which(pred element)is#fand returns everything that's left.Example:
(remove-if-not number? '(foo bar baz)) ⇒ () (remove-if-not odd? '(1 2 3 4 5 6 7 8)) ⇒ (1 3 5 7)
returns
#tif 2 members of lst areequal?,#fotherwise.Example:
(has-duplicates? '(1 2 3 4)) ⇒ #f (has-duplicates? '(2 4 3 4)) ⇒ #t
The procedure remove-duplicates uses member (rather than
memv).