diff --git a/pkgs/racket-doc/scribblings/reference/contracts.scrbl b/pkgs/racket-doc/scribblings/reference/contracts.scrbl index dac3eceb4c..2abc2bbdc6 100644 --- a/pkgs/racket-doc/scribblings/reference/contracts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/contracts.scrbl @@ -124,7 +124,8 @@ and how they can be used to implement contracts. @section[#:tag "data-structure-contracts"]{Data-structure Contracts} @declare-exporting-ctc[racket/contract/base] -@defproc[(flat-contract-with-explanation [get-explanation (-> any/c (or/c boolean? (-> blame? any)))]) +@defproc[(flat-contract-with-explanation [get-explanation (-> any/c (or/c boolean? (-> blame? any)))] + [#:name name any/c (object-name get-explanation)]) flat-contract?]{ Provides a way to use flat contracts that, when a contract fails, provide more information about the failure. @@ -133,7 +134,10 @@ and how they can be used to implement contracts. treated as the predicate in a @tech{flat contract}. If it returns a procedure, then it is treated similarly to returning @racket[#f], except the result procedure is called to actually signal the contract - violation. + violation. + + The @racket[name] argument is used as the name of the contract; it defaults + to the name of the @racket[get-explanation] function. @racketblock[(flat-contract-with-explanation (λ (val) diff --git a/pkgs/racket-test/tests/racket/contract/name.rkt b/pkgs/racket-test/tests/racket/contract/name.rkt index eded7340a6..bcea4d2547 100644 --- a/pkgs/racket-test/tests/racket/contract/name.rkt +++ b/pkgs/racket-test/tests/racket/contract/name.rkt @@ -64,6 +64,7 @@ (test-name 'kalidoscope (flat-named-contract 'kalidoscope exact-positive-integer?)) (test-name 'brick (flat-named-contract 'brick (integer-in 11 22))) + (test-name 'brick (flat-contract-with-explanation (let ([brick (λ (x) #t)]) brick))) (test-name '(-> integer? integer?) (-> integer? integer?)) (test-name '(-> integer? any) (-> integer? any)) diff --git a/racket/collects/racket/contract/private/misc.rkt b/racket/collects/racket/contract/private/misc.rkt index ac7b173287..cca9846f99 100644 --- a/racket/collects/racket/contract/private/misc.rkt +++ b/racket/collects/racket/contract/private/misc.rkt @@ -1062,7 +1062,7 @@ #:stronger (λ (this that) (contract-stronger? ctc that)) #:list-contract? (list-contract? ctc))) -(define (flat-contract-with-explanation ?) +(define (flat-contract-with-explanation ? #:name [name (object-name ?)]) (define (call-? x) (define reason (? x)) (unless (or (boolean? reason) @@ -1072,6 +1072,7 @@ (format "~s" '(or/c boolean? (-> blame? any))))) reason) (make-flat-contract + #:name name #:first-order (λ (x) (equal? #t (call-? x))) #:late-neg-projection (λ (b)