Next: srfi sets-and-bags whole, Previous: srfi sets-and-bags access, Up: srfi sets-and-bags [Index]
Return a newly allocated set that uses the same comparator as set and contains all the values of set, and in addition each element unless it is already equal (in the sense of the comparator) to one of the existing or newly added members.
It is an error to add an element for which the type test procedure
of the comparator does not return #t
.
(import (vicare) (srfi :113) (srfi :114)) (internal-body (define S (set fixnum-comparator 1 2 3)) (define S^ (set-adjoin S 4)) (list-sort fx<? (set->list S^))) ⇒ (1 2 3 4) (internal-body (define S (set fixnum-comparator 1 2 3)) (define S^ (set-adjoin S 2)) (list-sort fx<? (set->list S^))) ⇒ (1 2 3)
Return a newly allocated bag that uses the same comparator as bag and contains all the values of bag, and in addition each element.
It is an error to add an element for which the type test procedure
of the comparator does not return #t
.
(import (vicare) (srfi :113) (srfi :114)) (internal-body (define B (bag fixnum-comparator 1 2 3)) (define B^ (bag-adjoin B 4)) (list-sort fx<? (bag->list B^))) ⇒ (1 2 3 4) (internal-body (define B (bag fixnum-comparator 1 2 3)) (define B^ (bag-adjoin B 2)) (list-sort fx<? (bag->list B^))) ⇒ (1 2 2 3)
Like set-adjoin
and bag-adjoin
but they are permitted to
mutate and return set/bag rather than allocating a new set.
(import (vicare) (srfi :113) (srfi :114)) (internal-body (define S (set fixnum-comparator 1 2 3)) (set-adjoin! S 4) (list-sort fx<? (set->list S))) ⇒ (1 2 3 4) (internal-body (define S (set fixnum-comparator 1 2 3)) (set-adjoin! S 2) (list-sort fx<? (set->list S))) ⇒ (1 2 3) (internal-body (define B (bag fixnum-comparator 1 2 3)) (bag-adjoin! B 4) (list-sort fx<? (bag->list B))) ⇒ (1 2 3 4) (internal-body (define B (bag fixnum-comparator 1 2 3)) (bag-adjoin! B 2) (list-sort fx<? (bag->list B))) ⇒ (1 2 2 3)
Return a newly allocated set that uses the same comparator as set and contains all the values of set except that: if element is equal (in the sense of set’s comparator) to an existing member of set, then that member is omitted and replaced by element. If there is no such member in set, then set is returned unchanged.
Return a newly allocated bag that uses the same comparator as bag and contains all the values of bag except that: if element is equal (in the sense of bag’s comparator) to an existing member of bag, then that member is omitted and replaced by element. If there is no such member in bag, then bag is returned unchanged.
(import (vicare) (srfi :113) (srfi :114)) (define B (bag real-comparator 1 2 2 3)) (define B^ (bag-replace B 2.0)) (list-sort < (bag->list B^))) ⇒ (1 2.0 2.0 3)
Like set-replace
and bag-replace
but they are permitted to
mutate and return set or bag rather than allocating a new
set or bag.
Return a newly allocated set containing all the values of set except for any that are equal (in the sense of set’s comparator) to one or more of the elements. Any element that is not equal to some member of set is ignored.
Return a newly allocated bag containing all the values of bag except for any that are equal (in the sense of bag’s comparator) to one or more of the elements. Any element that is not equal to some member of bag is ignored.
(import (vicare) (srfi :113) (srfi :114)) (internal-body (define B (bag fixnum-comparator 1 2 2 3)) (define B^ (bag-delete B 2)) (list-sort < (bag->list B^))) ⇒ (1 2 3) (internal-body (define B (bag real-comparator 1 2 2 3)) (define B^ (bag-delete B 2.0)) (list-sort < (bag->list B^))) ⇒ (1 2 3)
Like set-delete
and bag-delete
but they are permitted to
mutate and return set and bag rather than allocating a new
set or bag.
Like set-delete
, bag-delete
, set-delete!
and
bag-delete!
but accept a single argument which is a list of
elements to be deleted.
The set or bag is searched for element.
The effects of the continuations are as follows (where obj is any Scheme object):
(insert obj)
causes element to be
inserted into set or bag.
(ignore obj)
causes set or bag
to remain unchanged.
(update new-element obj)
causes
new-element to be inserted into set or bag in place of
element.
(remove obj)
causes the matching element of
set or bag to be removed from it.
In all cases, two values are returned: the possibly updated set or bag and obj.
(import (vicare) (srfi :113) (srfi :114)) ;;success and update (internal-body (define S (set real-comparator 1 2 3)) (receive (S^ obj) (set-search! S 2.0 ;;failure proc (lambda (insert ignore) (error #f "wrong")) ;;success proc (lambda (true-element update remove) (update 9 'flag))) (list-sort < (set->list S^)) ⇒ (1 3 9) obj)) ⇒ flag ;;success and remove (internal-body (define S (set real-comparator 1 2 3)) (receive (S^ obj) (set-search! S 2.0 ;;failure proc (lambda (insert ignore) (error #f "wrong")) ;;success proc (lambda (true-element update remove) (remove 'flag))) (list-sort < (set->list S^)) ⇒ (1 3) obj)) ⇒ flag ;;failure and ignore (internal-body (define S (set real-comparator 1 2 3)) (receive (S^ obj) (set-search! S 99 ;;failure proc (lambda (insert ignore) (ignore 'flag)) ;;success proc (lambda (true-element update remove) (error #f "wrong"))) (list-sort < (set->list S^)) ⇒ (1 2 3) obj)) ⇒ flag ;;failure and insert (internal-body (define S (set real-comparator 1 2 3)) (receive (S^ obj) (set-search! S 99 ;;failure proc (lambda (insert ignore) (insert 'flag)) ;;success proc (lambda (true-element update remove) (error #f "wrong"))) (list-sort < (set->list S^)) ⇒ (1 2 3 99) obj)) ⇒ flag
Next: srfi sets-and-bags whole, Previous: srfi sets-and-bags access, Up: srfi sets-and-bags [Index]