From cf3b9680ba6725fd358ca2bf5f1b42d0e6f20a2a Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Mon, 29 Nov 2010 00:34:57 -0700 Subject: [PATCH] remove 0 arg set-union. add workaround to docs --- collects/racket/set.rkt | 7 ++++++- collects/scribblings/reference/sets.scrbl | 20 +++++++++++++++++++- collects/tests/racket/set.rktl | 2 -- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/collects/racket/set.rkt b/collects/racket/set.rkt index 0294a33570..db396d8b6b 100644 --- a/collects/racket/set.rkt +++ b/collects/racket/set.rkt @@ -111,7 +111,12 @@ (define set-union (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) (unless (set? set) (raise-type-error 'set-union "set" 0 set)) set] diff --git a/collects/scribblings/reference/sets.scrbl b/collects/scribblings/reference/sets.scrbl index 794b405d1f..8ec10d98fe 100644 --- a/collects/scribblings/reference/sets.scrbl +++ b/collects/scribblings/reference/sets.scrbl @@ -3,6 +3,8 @@ (for-label racket/set)) @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 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?], @scheme[eq?], or @scheme[eqv?]). This operation runs in time 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?]{ @@ -151,3 +168,4 @@ other forms.} Analogous to @scheme[for/list] and @scheme[for*/list], but to construct a set instead of a list.} +@close-eval[set-eval] diff --git a/collects/tests/racket/set.rktl b/collects/tests/racket/set.rktl index e8bd33675a..bb91761c34 100644 --- a/collects/tests/racket/set.rktl +++ b/collects/tests/racket/set.rktl @@ -17,8 +17,6 @@ (test #t set-empty? (seteqv)) (test #t set? (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-eqv? (set 1 2 3))