3.16 Sets
A set represents a set of distinct elements. For a given
set, elements are equivalent via equal?, eqv?, or
eq?. Two sets are equal? when they use the same
element-comparison procedure (equal?, eqv?, or
eq?) and have equivalent elements.
A set can be used as a single-valued sequence (see
Sequences). The elements of the set serve as elements
of the sequence. See also in-set.
Operations on sets that contain elements that are mutated are
unpredictable in much the same way that hash table operations are
unpredictable when keys are mutated.
Creates a set that uses
equal?,
eq?, or
eqv?, respectively, to compare elements. The given
vs are added to the set. The elements are added in the order
that they appear as
vs, so in the first two cases, an earlier
element that is
equal? or
eqv? but not
eq?
to a later element takes precedence over the later element.
Returns #t if st has no members, #f
otherwise.
Returns the number of elements in st.
Returns #t if v is in st, #f
otherwise.
Like operations on immutable hash tables, “constant
time” set operations actually require O(log N) time for a set
of size N.
Produces a set that includes v plus all elements of
st. This operation runs in constant time.
Produces a set that includes all elements of st except
v. This operation runs in constant time.
Produces a set that includes all elements of all given
sts,
which must all use the same equivalence predicate (
equal?,
eq?, or
eqv?). This operation runs in time
proportional to the total size of all given
sts except for
the largest.
At least one set must be provided to set-union even though
mathematically set-union could accept zero arguments. Since
there are multiple types of sets (eq?, eqv?, and
equal?) there is no obvious choice for a default empty set
to be returned. If there is a case where set-union may be
applied to zero arguments, instead pass an empty set of the type
you desire.
Produces a set that includes only the elements in all of the given
sts, which must all use the same equivalence predicate
(
equal?,
eq?, or
eqv?). This operation
runs in time proportional to the total size of all given
sts except for the largest.
Produces a set that includes all elements the first
sts that
are not present in any of the other given
stss. All of the
given
sts must use the same equivalence predicate
(
equal?,
eq?, or
eqv?). This operation
runs in time proportional to the total size of all given
sts except the first one.
Produces a set containing only those elements found in each
st an odd number of times. All of the given
sts must
use the same equivalence predicate (
equal?,
eq?, or
eqv?). This operation runs in time proportional to the total
size of all given
sts except the first one.
Returns
#t if
st and
st2 contain the same
members,
#f otherwise. The
st and
st2 must
use the same equivalence predicate (
equal?,
eq?, or
eqv?). This operation runs in time proportional to the size
of
st.
Equivalent to (equal? st st2).
Returns
#t if every member of
st is in
st2,
#f otherwise. The
st and
st2 must use the same equivalence predicate
(
equal?,
eq?, or
eqv?). This operation
runs in time proportional to the size of
st.
Returns
#t if every member of
st is in
st2
and there is some member of
st2 that is not a member of
st,
#f otherwise. The
st and
st2
must use the same equivalence predicate (
equal?,
eq?, or
eqv?). This operation runs in time
proportional to the size of
st.
Applies the procedure proc to each element in
st in an unspecified order, accumulating the results
into a list.
Applies proc to each element in st (for the
side-effects of proc) in an unspecified order.
Returns
#t if
v is a
set,
#f
otherwise.
Returns
#t if
st compares elements with
equal?,
#f if it compares with
eqv? or
eq?.
Returns
#t if
st compares elements with
eqv?,
#f if it compares with
equal? or
eq?.
Returns
#t if
st compares elements with
eq?,
#f if it compares with
equal? or
eqv?.
Constructs a contract that recognizes sets whose elements match contract.
If cmp is 'dont-care, then the equality notion of the set is not considered
when checking the contract. Otherwise, the contract accepts only sets with the corresponding
notion of equality.
If cmp is 'eq or 'eqv, then contract must be a flat contract.
If contract is not a flat contract, then cmp cannot be 'eq or 'eqv
and the resulting contract can only be applied to sets that use equal? for equality.
Explicitly converts a set to a sequence for use with
for and
other forms.
(for/set (for-clause ...) body ...+) |
|
|
|
|
|
|
Produces the appropriate type of set containing the elements of the
given list. Equivalent to
(apply set lst),
(apply seteq lst), and
(apply seteqv lst), respectively.
Produces a list containing the elements of st.