Changed set? to generic-set?.

This commit is contained in:
Carl Eastlund 2013-08-28 00:10:18 -04:00
parent 899d57f687
commit 6665f42e33
7 changed files with 146 additions and 139 deletions

View File

@ -210,6 +210,6 @@
([modidx module-path-index?]
[provide->toplevel (symbol? exact-nonnegative-integer? . -> . exact-nonnegative-integer?)])]
[get-modvar-rewrite/c contract?]
[current-excluded-modules (parameter/c set?)]
[current-excluded-modules (parameter/c generic-set?)]
[nodep-file (-> path-string?
(values compilation-top? lang-info/c module-path-index? get-modvar-rewrite/c))])

View File

@ -90,15 +90,15 @@ returns @racket[#f] otherwise.
}
@deftogether[(
@defproc[(set [v any/c] ...) (and/c set? set-equal? set-immutable?)]
@defproc[(seteqv [v any/c] ...) (and/c set? set-eqv? set-immutable?)]
@defproc[(seteq [v any/c] ...) (and/c set? set-eq? set-immutable?)]
@defproc[(mutable-set [v any/c] ...) (and/c set? set-equal? set-mutable?)]
@defproc[(mutable-seteqv [v any/c] ...) (and/c set? set-eqv? set-mutable?)]
@defproc[(mutable-seteq [v any/c] ...) (and/c set? set-eq? set-mutable?)]
@defproc[(weak-set [v any/c] ...) (and/c set? set-equal? set-weak?)]
@defproc[(weak-seteqv [v any/c] ...) (and/c set? set-eqv? set-weak?)]
@defproc[(weak-seteq [v any/c] ...) (and/c set? set-eq? set-weak?)]
@defproc[(set [v any/c] ...) (and/c generic-set? set-equal? set-immutable?)]
@defproc[(seteqv [v any/c] ...) (and/c generic-set? set-eqv? set-immutable?)]
@defproc[(seteq [v any/c] ...) (and/c generic-set? set-eq? set-immutable?)]
@defproc[(mutable-set [v any/c] ...) (and/c generic-set? set-equal? set-mutable?)]
@defproc[(mutable-seteqv [v any/c] ...) (and/c generic-set? set-eqv? set-mutable?)]
@defproc[(mutable-seteq [v any/c] ...) (and/c generic-set? set-eq? set-mutable?)]
@defproc[(weak-set [v any/c] ...) (and/c generic-set? set-equal? set-weak?)]
@defproc[(weak-seteqv [v any/c] ...) (and/c generic-set? set-eqv? set-weak?)]
@defproc[(weak-seteq [v any/c] ...) (and/c generic-set? set-eq? set-weak?)]
)]{
Creates a @tech{hash set} with the given @racket[v]s as elements. The
@ -110,15 +110,15 @@ replaced by a later element that is @racket[equal?] or @racket[eqv?] but not
}
@deftogether[(
@defproc[(list->set [lst list?]) (and/c set? set-equal? set-immutable?)]
@defproc[(list->seteqv [lst list?]) (and/c set? set-eqv? set-immutable?)]
@defproc[(list->seteq [lst list?]) (and/c set? set-eq? set-immutable?)]
@defproc[(list->mutable-set [lst list?]) (and/c set? set-equal? set-mutable?)]
@defproc[(list->mutable-seteqv [lst list?]) (and/c set? set-eqv? set-mutable?)]
@defproc[(list->mutable-seteq [lst list?]) (and/c set? set-eq? set-mutable?)]
@defproc[(list->weak-set [lst list?]) (and/c set? set-equal? set-weak?)]
@defproc[(list->weak-seteqv [lst list?]) (and/c set? set-eqv? set-weak?)]
@defproc[(list->weak-seteq [lst list?]) (and/c set? set-eq? set-weak?)]
@defproc[(list->set [lst list?]) (and/c generic-set? set-equal? set-immutable?)]
@defproc[(list->seteqv [lst list?]) (and/c generic-set? set-eqv? set-immutable?)]
@defproc[(list->seteq [lst list?]) (and/c generic-set? set-eq? set-immutable?)]
@defproc[(list->mutable-set [lst list?]) (and/c generic-set? set-equal? set-mutable?)]
@defproc[(list->mutable-seteqv [lst list?]) (and/c generic-set? set-eqv? set-mutable?)]
@defproc[(list->mutable-seteq [lst list?]) (and/c generic-set? set-eq? set-mutable?)]
@defproc[(list->weak-set [lst list?]) (and/c generic-set? set-equal? set-weak?)]
@defproc[(list->weak-seteqv [lst list?]) (and/c generic-set? set-eqv? set-weak?)]
@defproc[(list->weak-seteq [lst list?]) (and/c generic-set? set-eq? set-weak?)]
)]{
Creates a @tech{hash set} with the elements of the given @racket[lst] as
@ -155,22 +155,22 @@ construct a @tech{hash set} instead of a list.
@section{Set Predicates and Contracts}
@defproc[(set? [v any/c]) boolean?]{
@defproc[(generic-set? [v any/c]) boolean?]{
Returns @racket[#t] if @racket[v] is a @tech{set}; returns @racket[#f]
otherwise.
@examples[
#:eval set-eval
(set? (list 1 2 3))
(set? (set 1 2 3))
(set? (mutable-seteq 1 2 3))
(set? (vector 1 2 3))
(generic-set? (list 1 2 3))
(generic-set? (set 1 2 3))
(generic-set? (mutable-seteq 1 2 3))
(generic-set? (vector 1 2 3))
]
}
@defproc[(set-implements? [st set?] [sym symbol?] ...) boolean?]{
@defproc[(set-implements? [st generic-set?] [sym symbol?] ...) boolean?]{
Returns @racket[#t] if @racket[st] implements all of the methods from
@racket[gen:set] named by the @racket[sym]s; returns @racket[#f] otherwise.
@ -255,7 +255,7 @@ be used to implement any of the methods documented as
(bitwise-not (arithmetic-shift 1 i)))))])
(define bset (binary-set 5))
bset
(set? bset)
(generic-set? bset)
(set-member? bset 0)
(set-member? bset 1)
(set-member? bset 2)
@ -289,42 +289,42 @@ As an example, implementing the following methods would guarantee that all the m
There may be other such subsets of methods that would guarantee at least a fallback for every method.
@defproc[(set-member? [st set?] [v any/c]) boolean?]{
@defproc[(set-member? [st generic-set?] [v any/c]) boolean?]{
Returns @racket[#t] if @racket[v] is in @racket[st], @racket[#f]
otherwise. Has no fallback.
}
@defproc[(set-add [st set?] [v any/c]) set?]{
@defproc[(set-add [st generic-set?] [v any/c]) generic-set?]{
Produces a set that includes @racket[v] plus all elements of
@racket[st]. This operation runs in constant time for @tech{hash sets}. Has no fallback.
}
@defproc[(set-add! [st set?] [v any/c]) void?]{
@defproc[(set-add! [st generic-set?] [v any/c]) void?]{
Adds the element @racket[v] to @racket[st]. This operation runs in constant
time for @tech{hash sets}. Has no fallback.
}
@defproc[(set-remove [st set?] [v any/c]) set?]{
@defproc[(set-remove [st generic-set?] [v any/c]) generic-set?]{
Produces a set that includes all elements of @racket[st] except
@racket[v]. This operation runs in constant time for @tech{hash sets}. Has no fallback.
}
@defproc[(set-remove! [st set?] [v any/c]) void?]{
@defproc[(set-remove! [st generic-set?] [v any/c]) void?]{
Adds the element @racket[v] to @racket[st]. This operation runs in constant
time for @tech{hash sets}. Has no fallback.
}
@defproc[(set-empty? [st set?]) boolean?]{
@defproc[(set-empty? [st generic-set?]) boolean?]{
Returns @racket[#t] if @racket[st] has no members; returns @racket[#f]
otherwise.
@ -334,7 +334,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set->stream] or
}
@defproc[(set-count [st set?]) exact-nonnegative-integer?]{
@defproc[(set-count [st generic-set?]) exact-nonnegative-integer?]{
Returns the number of elements in @racket[st].
@ -342,7 +342,7 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream].
}
@defproc[(set-first [st (and/c set? (not/c set-empty?))]) any/c]{
@defproc[(set-first [st (and/c generic-set? (not/c set-empty?))]) any/c]{
Produces an unspecified element of @racket[st]. Multiple uses of
@racket[set-first] on @racket[st] produce the same result.
@ -352,7 +352,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set->stream].
}
@defproc[(set-rest [st (and/c set? (not/c set-empty?))]) set?]{
@defproc[(set-rest [st (and/c generic-set? (not/c set-empty?))]) generic-set?]{
Produces a set that includes all elements of @racket[st] except
@racket[(set-first st)].
@ -362,7 +362,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove] and eit
}
@defproc[(set->stream [st set?]) stream?]{
@defproc[(set->stream [st generic-set?]) stream?]{
Produces a stream containing the elements of @racket[st].
@ -375,7 +375,7 @@ Supported for any @racket[st] that @impl{implements}:
@item{@racket[set-count], @racket[set-first], @racket[set-remove]}]
}
@defproc[(set-copy [st set?]) set?]{
@defproc[(set-copy [st generic-set?]) generic-set?]{
Produces a new, mutable set of the same type and with the same elements as
@racket[st].
@ -385,7 +385,7 @@ either @impl{implements} @racket[set-copy-clear] and @racket[set-add!].
}
@defproc[(set-copy-clear [st set?]) (and/c set? set-empty?)]{
@defproc[(set-copy-clear [st generic-set?]) (and/c generic-set? set-empty?)]{
Produces a new, empty set of the same type, mutability, and key strength as
@racket[st].
@ -401,7 +401,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove] and @su
}
@defproc[(set-clear [st set?]) (and/c set? set-empty?)]{
@defproc[(set-clear [st generic-set?]) (and/c generic-set? set-empty?)]{
Produces set by removing all elements of @racket[st].
@ -410,7 +410,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove] and @su
}
@defproc[(set-clear! [st set?]) void?]{
@defproc[(set-clear! [st generic-set?]) void?]{
Removes all elements from @racket[st].
@ -419,7 +419,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove!] and ei
}
@defproc[(set-union [st0 set?] [st set?] ...) set?]{
@defproc[(set-union [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Produces a set of the same type as @racket[st0] that includes the elements from
@racket[st0] and all of the @racket[st]s.
@ -449,7 +449,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-add] and @supp
(set-union (set 1 2) (seteq 2 3)) (code:comment "Sets of different types cannot be unioned.")
]}
@defproc[(set-union! [st0 set?] [st set?] ...) set?]{
@defproc[(set-union! [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Adds the elements from all of the @racket[st]s to @racket[st0].
@ -463,7 +463,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-add!] and @supp
}
@defproc[(set-intersect [st0 set?] [st set?] ...) set?]{
@defproc[(set-intersect [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Produces a set of the same type as @racket[st0] that includes the elements from
@racket[st0] that are also contained by all of the @racket[st]s.
@ -483,7 +483,7 @@ both @racket[set-clear] and @racket[set-add], and @supp{supports} @racket[set->s
}
@defproc[(set-intersect! [st0 set?] [st set?] ...) set?]{
@defproc[(set-intersect! [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Removes every element from @racket[st0] that is not contained by all of the
@racket[st]s.
@ -498,7 +498,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove!] and @s
}
@defproc[(set-subtract [st0 set?] [st set?] ...) set?]{
@defproc[(set-subtract [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Produces a set of the same type as @racket[st0] that includes the elements from
@racket[st0] that not contained by any of the @racket[st]s.
@ -518,7 +518,7 @@ both @racket[set-clear] and @racket[set-add], and @supp{supports} @racket[set->s
}
@defproc[(set-subtract! [st0 set?] [st set?] ...) set?]{
@defproc[(set-subtract! [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Removes every element from @racket[st0] that is contained by any of the
@racket[st]s.
@ -533,7 +533,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove!] and @s
}
@defproc[(set-symmetric-difference [st0 set?] [st set?] ...) set?]{
@defproc[(set-symmetric-difference [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Produces a set of the same type as @racket[st0] that includes all of the
elements contained an even number of times in @racket[st0] and the
@ -557,7 +557,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove] or both
}
@defproc[(set-symmetric-difference! [st0 set?] [st set?] ...) set?]{
@defproc[(set-symmetric-difference! [st0 generic-set?] [st generic-set?] ...) generic-set?]{
Adds and removes elements of @racket[st0] so that it includes all of the
elements contained an even number of times in the @racket[st]s and the
@ -573,7 +573,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-remove!] and @s
}
@defproc[(set=? [st set?] [st2 set?]) boolean?]{
@defproc[(set=? [st generic-set?] [st2 generic-set?]) boolean?]{
Returns @racket[#t] if @racket[st] and @racket[st2] contain the same
members; returns @racket[#f] otherwise.
@ -604,7 +604,7 @@ be compared.")
}
@defproc[(subset? [st set?] [st2 set?]) boolean?]{
@defproc[(subset? [st generic-set?] [st2 generic-set?]) boolean?]{
Returns @racket[#t] if @racket[st2] contains every member of @racket[st];
returns @racket[#f] otherwise.
@ -629,7 +629,7 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream].
}
@defproc[(proper-subset? [st set?] [st2 set?]) boolean?]{
@defproc[(proper-subset? [st generic-set?] [st2 generic-set?]) boolean?]{
Returns @racket[#t] if @racket[st2] contains every member of @racket[st] and at
least one additional element; returns @racket[#f] otherwise.
@ -655,7 +655,7 @@ Supported for any @racket[st] and @racket[st2] that both @supp{support}
}
@defproc[(set->list [st set?]) list?]{
@defproc[(set->list [st generic-set?]) list?]{
Produces a list containing the elements of @racket[st].
@ -663,7 +663,7 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream].
}
@defproc[(set-map [st set?]
@defproc[(set-map [st generic-set?]
[proc (any/c . -> . any/c)])
(listof any/c)]{
@ -676,7 +676,7 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream].
}
@defproc[(set-for-each [st set?]
@defproc[(set-for-each [st generic-set?]
[proc (any/c . -> . any)])
void?]{
@ -687,7 +687,7 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream].
}
@defproc[(in-set [st set?]) sequence?]{
@defproc[(in-set [st generic-set?]) sequence?]{
Explicitly converts a set to a sequence for use with @racket[for] and
other forms.
@ -748,8 +748,8 @@ initial elements.
(make-immutable-string-set '("apple" "banana")))
(define mut
(make-mutable-string-set '("apple" "banana")))
(set? imm)
(set? mut)
(generic-set? imm)
(generic-set? mut)
(string-set? imm)
(string-set? mut)
(immutable-string-set? imm)
@ -785,9 +785,9 @@ initial elements.
(any/c . -> . boolean?)
(any/c . -> . boolean?)
(any/c . -> . boolean?)
(->* [] [stream?] set?)
(->* [] [stream?] set?)
(->* [] [stream?] set?))]{
(->* [] [stream?] generic-set?)
(->* [] [stream?] generic-set?)
(->* [] [stream?] generic-set?))]{
Creates a new set type based on the given comparison function @racket[eql?],
hash functions @racket[hash1] and @racket[hash2], and predicate @racket[elem?].

View File

@ -516,7 +516,7 @@
(define (atom? x)
(or* x boolean? number? string? bytes? char? symbol?
regexp? pregexp? byte-regexp? byte-pregexp?
keyword? null? procedure? void? set?
keyword? null? procedure? void? generic-set?
atomic-struct?))
(define (compound? x)
(or* x pair? vector? mpair? box? hash? compound-struct?))

View File

@ -1047,7 +1047,7 @@
[proper-subset? (-poly (e) (-> (-set e) (-set e) B))]
[set-map (-poly (e b) (-> (-set e) (-> e b) (-lst b)))]
[set-for-each (-poly (e b) (-> (-set e) (-> e b) -Void))]
[set? (make-pred-ty (-set Univ))]
[generic-set? (make-pred-ty (-set Univ))]
[set-equal? (-poly (e) (-> (-set e) B))]
[set-eqv? (-poly (e) (-> (-set e) B))]
[set-eq? (-poly (e) (-> (-set e) B))]

View File

@ -45,8 +45,8 @@
(define (custom-set=? s1 s2)
(dprintf "custom-set=?\n")
(unless (set? s2)
(raise-argument-error 'set=? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'set=? "generic-set?" 1 s1 s2))
(set-check-compatible 'set=? s1 s2)
(define table1 (custom-set-table s1))
(define table2 (custom-set-table s2))
@ -57,8 +57,8 @@
(define (custom-subset? s1 s2)
(dprintf "custom-subset?\n")
(unless (set? s2)
(raise-argument-error 'subset? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'subset? "generic-set?" 1 s1 s2))
(set-check-compatible 'subset? s1 s2)
(define table1 (custom-set-table s1))
(define table2 (custom-set-table s2))
@ -67,8 +67,8 @@
(define (custom-proper-subset? s1 s2)
(dprintf "custom-proper-subset?\n")
(unless (set? s2)
(raise-argument-error 'proper-subset? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'proper-subset? "generic-set?" 1 s1 s2))
(set-check-compatible 'proper-subset? s1 s2)
(define table1 (custom-set-table s1))
(define table2 (custom-set-table s2))
@ -105,7 +105,7 @@
(define table (custom-set-table s))
(define i (hash-iterate-first table))
(unless i
(raise-argument-error 'set-first "(and/c set? (not/c set-empty?))" s))
(raise-argument-error 'set-first "(and/c generic-set? (not/c set-empty?))" s))
(set-unwrap-key s (hash-iterate-key table i)))
(define (custom-set-rest s)
@ -113,7 +113,7 @@
(define table (custom-set-table s))
(define i (hash-iterate-first table))
(unless i
(raise-argument-error 'set-rest "(and/c set? (not/c set-empty?))" s))
(raise-argument-error 'set-rest "(and/c generic-set? (not/c set-empty?))" s))
(update-custom-set-table s (hash-remove table (hash-iterate-key table i))))
(define (custom-set-add s x)
@ -140,8 +140,8 @@
(define (choose-immutable who better? set0 sets)
(for/fold ([largest set0]) ([s (in-list sets)] [i (in-naturals 1)])
(unless (set? s)
(apply raise-argument-error who "set?" i set0 sets))
(unless (generic-set? s)
(apply raise-argument-error who "generic-set?" i set0 sets))
(set-check-compatible who set0 s)
(if (and (immutable? (custom-set-table s))
(better? (hash-count (custom-set-table s))
@ -204,8 +204,8 @@
(define (custom-set-subtract s . sets)
(dprintf "custom-set-subtract\n")
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-subtract "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-subtract "generic-set?" i s sets))
(set-check-compatible 'set-subtract s s2))
(define (remove? k)
(for/or ([s2 (in-list sets)])
@ -238,8 +238,8 @@
(define table (custom-set-table s))
(for ([s2 (in-list sets)]
[i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-union! "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-union! "generic-set?" i s sets))
(set-check-compatible 'set-union! s s2)
(for ([x (in-hash-keys (custom-set-table s2))])
(hash-set! table x #t))))
@ -249,8 +249,8 @@
(define table (custom-set-table s))
(for ([s2 (in-list sets)]
[i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-symmetric-difference! "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-symmetric-difference! "generic-set?" i s sets))
(set-check-compatible 'set-symmetric-difference! s s2)
(for ([x (in-hash-keys (custom-set-table s2))])
(if (hash-ref table x #f)
@ -261,8 +261,8 @@
(dprintf "custom-set-intersect!\n")
(define tables
(for/list ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-intersect! "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-intersect! "generic-set?" i s sets))
(set-check-compatible 'set-intersect! s s2)
(custom-set-table s2)))
(define (keep? k)
@ -280,8 +280,8 @@
(dprintf "custom-set-subtract!\n")
(define tables
(for/list ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-subtract! "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-subtract! "generic-set?" i s sets))
(set-check-compatible 'set-subtract! s s2)
(custom-set-table s2)))
(define (remove? k)

View File

@ -4,7 +4,7 @@
racket/stream
(for-syntax racket/base))
(provide gen:set set? set-implements?
(provide gen:set generic-set? set-implements?
set-empty? set-member? set-count
set=? subset? proper-subset?
@ -56,7 +56,7 @@
(define (list-union s . sets)
(for/fold ([s1 s]) ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(unless (generic-set? s2)
(apply raise-argument-error 'set-union "list?" i s sets))
(for/fold ([s1 s1]) ([x (in-list s2)])
(list-add s1 x))))
@ -195,8 +195,8 @@
(for/sum ([x (*in-set s)]) 1))
(define (fallback-set=? s1 s2)
(unless (set? s2)
(raise-argument-error 'set=? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'set=? "generic-set?" 1 s1 s2))
(or (eq? s1 s2)
(cond
[(set-implements? s2 'set=?) (set=? s1 s2)]
@ -204,14 +204,14 @@
(subset? s2 s1))])))
(define (fallback-proper-subset? s1 s2)
(unless (set? s2)
(raise-argument-error 'proper-subset? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'proper-subset? "generic-set?" 1 s1 s2))
(and (subset? s1 s2)
(not (subset? s2 s1))))
(define (fallback-subset? s1 s2)
(unless (set? s2)
(raise-argument-error 'subset? "set?" 1 s1 s2))
(unless (generic-set? s2)
(raise-argument-error 'subset? "generic-set?" 1 s1 s2))
(for/and ([x (*in-set s1)])
(set-member? s2 x)))
@ -247,16 +247,16 @@
(cond
[(set-implements? s 'set-add)
(for/fold ([s1 s]) ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-union "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-union "generic-set?" i s sets))
(for/fold ([s1 s1]) ([x (*in-set s2)])
(set-add s1 x)))]
[else (raise-support-error 'set-union s)]))
(define (fallback-intersect s . sets)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-intersect "set?" i s sets)))
(unless (generic-set? s2)
(apply raise-argument-error 'set-intersect "generic-set?" i s sets)))
(define (keep? x)
(for/and ([s2 (in-list sets)])
(set-member? s2 x)))
@ -271,8 +271,8 @@
(define (fallback-subtract s . sets)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-subtract "set?" i s sets)))
(unless (generic-set? s2)
(apply raise-argument-error 'set-subtract "generic-set?" i s sets)))
(define (remove? x)
(for/or ([s2 (in-list sets)])
(set-member? s2 x)))
@ -287,8 +287,13 @@
(define (fallback-symmetric-difference s . sets)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-symmetric-difference "set?" i s sets)))
(unless (generic-set? s2)
(apply raise-argument-error
'set-symmetric-difference
"generic-set?"
i
s
sets)))
(define (keep? x)
(even?
(for/sum ([s2 (in-list sets)]
@ -330,8 +335,8 @@
(cond
[(set-implements? s 'set-add!)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-union! "set?" i s sets))
(unless (generic-set? s2)
(apply raise-argument-error 'set-union! "generic-set?" i s sets))
(for ([x (*in-set s2)])
(set-add! s x)))]
[else (raise-support-error 'set-union! s)]))
@ -340,8 +345,8 @@
(cond
[(set-implements? s 'set-remove!)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-intersect! "set?" i s sets)))
(unless (generic-set? s2)
(apply raise-argument-error 'set-intersect! "generic-set?" i s sets)))
(define (keep? x)
(for/and ([s2 (in-list sets)])
(set-member? s2 x)))
@ -356,8 +361,8 @@
(cond
[(set-implements? s 'set-remove!)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(apply raise-argument-error 'set-subtract! "set?" i s sets)))
(unless (generic-set? s2)
(apply raise-argument-error 'set-subtract! "generic-set?" i s sets)))
(define (remove? x)
(for/or ([s2 (in-list sets)])
(set-member? s2 x)))
@ -372,9 +377,9 @@
(cond
[(set-implements? s 'set-remove!)
(for ([s2 (in-list sets)] [i (in-naturals 1)])
(unless (set? s2)
(unless (generic-set? s2)
(define name 'set-symmetric-difference!)
(apply raise-argument-error name "set?" i s sets)))
(apply raise-argument-error name "generic-set?" i s sets)))
(define (keep? x)
(even?
(for/sum ([s2 (in-list sets)]
@ -397,11 +402,11 @@
(define (set-implements/c . syms)
(if (null? syms)
set?
generic-set?
(flat-named-contract
`(set-implements/c . ,syms)
(lambda (x)
(and (set? x)
(and (generic-set? x)
(for/and ([sym (in-list syms)])
(set-implements? x sym)))))))
@ -488,3 +493,5 @@
(define set-intersect! fallback-intersect!)
(define set-subtract! fallback-subtract!)
(define set-symmetric-difference! fallback-symmetric-difference!)])
(define (generic-set? x) (set? x))

View File

@ -83,10 +83,10 @@
[(weak) set-weak?]
[(immutable) set-immutable?]))
(lambda (x)
(and (set? x) (cmp? x) (kind? x))))
(and (generic-set? x) (cmp? x) (kind? x))))
(define (set-contract-check cmp kind b x)
(unless (set? x)
(unless (generic-set? x)
(raise-blame-error b x "expected a set"))
(case cmp
[(equal)
@ -136,43 +136,43 @@
(define-syntax-rule (redirect [id expr] ...)
(redirect-generics mode gen:set x [id (method 'id expr)] ...))
(redirect
[set-member? (-> set? elem/c boolean?)]
[set-empty? (or/c (-> set? boolean?) #f)]
[set-count (or/c (-> set? exact-nonnegative-integer?) #f)]
[set=? (or/c (-> set? ctc boolean?) #f)]
[subset? (or/c (-> set? ctc boolean?) #f)]
[proper-subset? (or/c (-> set? ctc boolean?) #f)]
[set-map (or/c (-> set? (-> elem/c any/c) list?) #f)]
[set-for-each (or/c (-> set? (-> elem/c any) void?) #f)]
[set-copy (or/c (-> set? set?) #f)]
[in-set (or/c (-> set? sequence?) #f)]
[set->list (or/c (-> set? (listof elem/c)) #f)]
[set->stream (or/c (-> set? stream?) #f)]
[set-first (or/c (-> set? elem/c) #f)]
[set-rest (or/c (-> set? ctc) #f)]
[set-add (or/c (-> set? elem/c ctc) #f)]
[set-remove (or/c (-> set? elem/c ctc) #f)]
[set-clear (or/c (-> set? ctc) #f)]
[set-copy-clear (or/c (-> set? set?) #f)]
[set-member? (-> generic-set? elem/c boolean?)]
[set-empty? (or/c (-> generic-set? boolean?) #f)]
[set-count (or/c (-> generic-set? exact-nonnegative-integer?) #f)]
[set=? (or/c (-> generic-set? ctc boolean?) #f)]
[subset? (or/c (-> generic-set? ctc boolean?) #f)]
[proper-subset? (or/c (-> generic-set? ctc boolean?) #f)]
[set-map (or/c (-> generic-set? (-> elem/c any/c) list?) #f)]
[set-for-each (or/c (-> generic-set? (-> elem/c any) void?) #f)]
[set-copy (or/c (-> generic-set? generic-set?) #f)]
[in-set (or/c (-> generic-set? sequence?) #f)]
[set->list (or/c (-> generic-set? (listof elem/c)) #f)]
[set->stream (or/c (-> generic-set? stream?) #f)]
[set-first (or/c (-> generic-set? elem/c) #f)]
[set-rest (or/c (-> generic-set? ctc) #f)]
[set-add (or/c (-> generic-set? elem/c ctc) #f)]
[set-remove (or/c (-> generic-set? elem/c ctc) #f)]
[set-clear (or/c (-> generic-set? ctc) #f)]
[set-copy-clear (or/c (-> generic-set? generic-set?) #f)]
[set-union
(or/c (->* [set?] [] #:rest (listof ctc) ctc) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) ctc) #f)]
[set-intersect
(or/c (->* [set?] [] #:rest (listof ctc) ctc) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) ctc) #f)]
[set-subtract
(or/c (->* [set?] [] #:rest (listof ctc) ctc) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) ctc) #f)]
[set-symmetric-difference
(or/c (->* [set?] [] #:rest (listof ctc) ctc) #f)]
[set-add! (or/c (-> set? elem/c void?) #f)]
[set-remove! (or/c (-> set? elem/c void?) #f)]
[set-clear! (or/c (-> set? void?) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) ctc) #f)]
[set-add! (or/c (-> generic-set? elem/c void?) #f)]
[set-remove! (or/c (-> generic-set? elem/c void?) #f)]
[set-clear! (or/c (-> generic-set? void?) #f)]
[set-union!
(or/c (->* [set?] [] #:rest (listof ctc) void?) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) void?) #f)]
[set-intersect!
(or/c (->* [set?] [] #:rest (listof ctc) void?) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) void?) #f)]
[set-subtract!
(or/c (->* [set?] [] #:rest (listof ctc) void?) #f)]
(or/c (->* [generic-set?] [] #:rest (listof ctc) void?) #f)]
[set-symmetric-difference!
(or/c (->* [set?] [] #:rest (listof ctc) void?) #f)])])))))
(or/c (->* [generic-set?] [] #:rest (listof ctc) void?) #f)])])))))
(define (flat-set-contract-first-order ctc)
(define set-passes? (set-contract-first-order ctc))