Coerce the arg in contract-random-generate/choose
This commit is contained in:
parent
d9218abc71
commit
40b8ae7a33
|
@ -3567,8 +3567,14 @@ ended up returning @racket[contract-random-generate-fail].
|
|||
(or/c #f (-> c))]{
|
||||
This function is like @racket[contract-random-generate], but it is intended to
|
||||
be used with combinators that generate values based on sub-contracts
|
||||
they have. It cannot be called, except during contract
|
||||
generation. It will never fail, but it might escape back to an enclosing
|
||||
they have. It must be called when @racket[contract-random-generate]
|
||||
(and @racket[contract-exercise]) creates the generators. In other words,
|
||||
@racket[contract-random-generate/choose] is available only after the
|
||||
@racket[_generate] (and @racket[_exercise]) function received the
|
||||
@racket[_fuel] and before it returned the thunk (or the exerciser).
|
||||
|
||||
@racket[contract-random-generate/choose] will never fail,
|
||||
but it might escape back to an enclosing
|
||||
call or to the original call to @racket[contract-random-generate].
|
||||
|
||||
It chooses one of several possible generation strategies, and thus it may not
|
||||
|
|
|
@ -492,3 +492,14 @@
|
|||
(λ (_) 'thing)
|
||||
'pos
|
||||
'neg))
|
||||
|
||||
;; a test for contract-random-generate/choose
|
||||
(let ()
|
||||
(struct make-gen-choose/c ()
|
||||
#:property prop:chaperone-contract
|
||||
(build-chaperone-contract-property
|
||||
#:late-neg-projection
|
||||
(λ (ctc) (λ (b) (λ (v np) v)))
|
||||
#:generate
|
||||
(λ (ctc) (λ (fuel) (contract-random-generate/choose number? 10)))))
|
||||
(check-not-exn (λ () (test-contract-generation (make-gen-choose/c)))))
|
||||
|
|
|
@ -194,7 +194,8 @@
|
|||
; #f if no value could be generated
|
||||
;; if it returns a thunk, the thunk will not return contract-random-generate-fail?
|
||||
(define (contract-random-generate/choose ctc fuel)
|
||||
(define direct ((contract-struct-generate ctc) fuel))
|
||||
(define def-ctc (coerce-contract 'contract-random-generate/choose ctc))
|
||||
(define direct ((contract-struct-generate def-ctc) fuel))
|
||||
(define env-can? (can-generate/env? ctc))
|
||||
(define env (generate-env))
|
||||
(unless (contract-random-generate-env? env)
|
||||
|
|
Loading…
Reference in New Issue
Block a user