From daf19869de0e0c512305c389695ba929697cfb5a Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sat, 26 Dec 2015 22:05:29 -0600 Subject: [PATCH] chaperone-hash-set fixes --- pkgs/racket-doc/scribblings/reference/sets.scrbl | 8 ++++---- pkgs/racket-test-core/tests/racket/set.rktl | 5 +++++ racket/collects/racket/private/set-types.rkt | 9 +++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/sets.scrbl b/pkgs/racket-doc/scribblings/reference/sets.scrbl index 8f8aefc29c..966eb7238e 100644 --- a/pkgs/racket-doc/scribblings/reference/sets.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sets.scrbl @@ -699,11 +699,11 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream]. [ref-proc (-> set? any/c any/c)] [add-proc (-> set? any/c any/c)] [remove-proc (-> set? any/c any/c)] - [clear-proc (or/c #f (-> set? any))] + [clear-proc (or/c #f (-> set? any)) #f] [prop impersonator-property?] [prop-val any/c] ... ...) (and/c set? impersonator?)]{ - Impersonates @racket[set], redirecting via the given procedures. + Impersonates @racket[st], redirecting via the given procedures. The @racket[ref-proc] procedure is called whenever an element is extracted from @racket[st]. Its first argument @@ -737,11 +737,11 @@ Supported for any @racket[st] that @supp{supports} @racket[set->stream]. [ref-proc (-> set? any/c any/c)] [add-proc (-> set? any/c any/c)] [remove-proc (-> set? any/c any/c)] - [clear-proc (or/c #f (-> set? any))] + [clear-proc (or/c #f (-> set? any)) #f] [prop impersonator-property?] [prop-val any/c] ... ...) (and/c set? chaperone?)]{ - Chaperones @racket[set]. Like @racket[impersonate-hash-set] but with + Chaperones @racket[st]. Like @racket[impersonate-hash-set] but with the constraints that the results of the @racket[ref-proc], @racket[add-proc], and @racket[remove-proc] must be @racket[chaperone-of?] their second arguments. Also, the input diff --git a/pkgs/racket-test-core/tests/racket/set.rktl b/pkgs/racket-test-core/tests/racket/set.rktl index 3322a3d996..c1a3eb5c5c 100644 --- a/pkgs/racket-test-core/tests/racket/set.rktl +++ b/pkgs/racket-test-core/tests/racket/set.rktl @@ -631,5 +631,10 @@ (λ (s e) (+ e 1)) (λ (s l) l) (λ (s l) l)))) +(test #t even? + (set-first (impersonate-hash-set (weak-set 1 3 5) + (λ (s e) (+ e 1)) + (λ (s l) l) + (λ (s l) l)))) (report-errs) diff --git a/racket/collects/racket/private/set-types.rkt b/racket/collects/racket/private/set-types.rkt index 7192549c45..08f52577ee 100644 --- a/racket/collects/racket/private/set-types.rkt +++ b/racket/collects/racket/private/set-types.rkt @@ -403,10 +403,15 @@ remove-proc clear-proc+props) (define who (if impersonate? 'impersonate-hash-set 'chaperone-hash-set)) - (unless (if impersonate? (set-mutable? s) (or (set? s) (set-mutable? s))) + (unless (if impersonate? + (or (set-mutable? s) (set-weak? s)) + (or (set? s) (set-mutable? s) (set-weak? s))) (apply raise-argument-error who - (if impersonate? "set-mutable?" (format "~s" '(or/c set? set-mutable?))) + (format "~s" + (if impersonate? + '(or/c set-mutable? set-weak?) + '(or/c set? set-mutable? set-weak?))) 0 s ref-proc add-proc clear-proc+props)) (unless (and (procedure? ref-proc) (procedure-arity-includes? ref-proc 2))