remove 0 arg set-union. add workaround to docs

This commit is contained in:
Jon Rafkind 2010-11-29 00:34:57 -07:00
parent 46244f81fc
commit cf3b9680ba
3 changed files with 25 additions and 4 deletions

View File

@ -111,7 +111,12 @@
(define set-union (define set-union
(case-lambda (case-lambda
[() (set)] ;; No 0 argument set exists because its not clear what type of set
;; to return. A keyword is unsatisfactory because it may be hard to
;; remember. A simple solution is just to provide the type of the
;; empty set that you want, like (set-union (set)) or
;; (set-union (set-eqv))
;; [() (set)]
[(set) [(set)
(unless (set? set) (raise-type-error 'set-union "set" 0 set)) (unless (set? set) (raise-type-error 'set-union "set" 0 set))
set] set]

View File

@ -3,6 +3,8 @@
(for-label racket/set)) (for-label racket/set))
@title[#:tag "sets"]{Sets} @title[#:tag "sets"]{Sets}
@(define set-eval (make-base-eval))
@(interaction-eval #:eval set-eval (require racket/set))
A @deftech{set} represents a set of distinct elements. For a given A @deftech{set} represents a set of distinct elements. For a given
set, elements are equivalent via @scheme[equal?], @scheme[eqv?], or set, elements are equivalent via @scheme[equal?], @scheme[eqv?], or
@ -86,7 +88,22 @@ Produces a set that includes all elements of all given @scheme[set]s,
which must all use the same equivalence predicate (@scheme[equal?], which must all use the same equivalence predicate (@scheme[equal?],
@scheme[eq?], or @scheme[eqv?]). This operation runs in time @scheme[eq?], or @scheme[eqv?]). This operation runs in time
proportional to the total size of all given @scheme[set]s except for proportional to the total size of all given @scheme[set]s except for
the largest.} the largest.
At least one set must be provided to @racket[set-union] even though
mathematically @racket[set-union] could accept zero arguments. Since
there are multiple types of sets (@racket[eq?], @racket[eqv?], and
@racket[equal?]) there is no obvious choice for a default empty set
to be returned. If there is a case where @racket[set-union] may be
applied to zero arguments, instead pass an empty set of the type
you desire.
@examples[#:eval set-eval
(set-union (set))
(set-union (seteq))
(set-union (set 1) (set 2))
(set-union (set 1) (seteq 2)) (code:comment "Sets of different types cannot be unioned")
]}
@defproc[(set-intersect [set set?] ...+) set?]{ @defproc[(set-intersect [set set?] ...+) set?]{
@ -151,3 +168,4 @@ other forms.}
Analogous to @scheme[for/list] and @scheme[for*/list], but to Analogous to @scheme[for/list] and @scheme[for*/list], but to
construct a set instead of a list.} construct a set instead of a list.}
@close-eval[set-eval]

View File

@ -17,8 +17,6 @@
(test #t set-empty? (seteqv)) (test #t set-empty? (seteqv))
(test #t set? (seteqv 1 2 3)) (test #t set? (seteqv 1 2 3))
(test #f set-empty? (seteqv 1 2 3)) (test #f set-empty? (seteqv 1 2 3))
(test #t set? (set-union))
(test #t set-empty? (set-union))
(test #f set-eq? (set 1 2 3)) (test #f set-eq? (set 1 2 3))
(test #f set-eqv? (set 1 2 3)) (test #f set-eqv? (set 1 2 3))