Next: srfi sets-and-bags preds, Previous: srfi sets-and-bags intro, Up: srfi sets-and-bags [Index]
Return a newly allocated empty set. comparator is a SRFI-114 comparator, which is used to control and distinguish the elements of the set. The elements are used to initialize the set.
(import (vicare) (srfi :113) (srfi :114)) (define S (set fixnum-comparator 1 2 3)) (values (set-contains? S 1) (set-contains? S 2) (set-contains? S 3) (set-size S)) ⇒ #t #t #t 3 (define B (bag fixnum-comparator 1 2 3 2)) (values (bag-contains? B 1) (bag-contains? B 2) (bag-contains? B 3) (bag-size B)) ⇒ #t #t #t 4
Create a newly allocated set as if by set
or bag
using
comparator. If the result of applying the predicate stop?
to seed is true, return the set. Otherwise, apply the procedure
mapper to seed. The value that mapper returns is
added to the set. Then get a new seed by applying the procedure
successor to seed, and repeat this algorithm.
(import (vicare) (srfi :113) (srfi :114)) (define (stop? seed) (fx>? seed 3)) (define (mapper seed) (number->string seed)) (define (successor seed) (fxadd1 seed)) (define S (set-unfold string-comparator stop? mapper successor 1)) (values (set-contains? S "1") (set-contains? S "2") (set-contains? S "3") (set-size S))) ⇒ #t #t #t 3 (define B (bag-unfold string-comparator stop? mapper successor 1)) (values (bag-contains? B "1") (bag-contains? B "2") (bag-contains? B "3") (bag-size B))) ⇒ #t #t #t 3