noticed some @tech{} cleanup opportunities and added some examples
for the random generation functionality
This commit is contained in:
parent
c4ebd771bb
commit
be628e21a6
|
@ -110,11 +110,11 @@ Contracts in Racket are subdivided into three different categories:
|
||||||
may hide properties of values, or even make them completely
|
may hide properties of values, or even make them completely
|
||||||
opaque (e.g, @racket[new-∀/c]).
|
opaque (e.g, @racket[new-∀/c]).
|
||||||
|
|
||||||
All contracts are impersonator contracts.}]
|
All @tech{contracts} are impersonator contracts.}]
|
||||||
|
|
||||||
For more about this hierarchy, see @tech{chaperones} and
|
For more about this hierarchy, see the section ``@secref["chaperones"]''
|
||||||
a research paper on chaperones, impersonators, and how they can be used to
|
as well as a research paper @cite{Strickland12} on chaperones, impersonators,
|
||||||
implement contracts @cite{Strickland12}.
|
and how they can be used to implement contracts.
|
||||||
|
|
||||||
@history[#:changed "6.1.1.8" @list{Changed @racket[+nan.0] and @racket[+nan.f] to
|
@history[#:changed "6.1.1.8" @list{Changed @racket[+nan.0] and @racket[+nan.f] to
|
||||||
be @racket[equal?]-based contracts.}]
|
be @racket[equal?]-based contracts.}]
|
||||||
|
@ -3209,6 +3209,10 @@ it is called with @racket[#t] when there is no generator for @racket[ctc]
|
||||||
and called with @racket[#f] when there is a generator, but the generator
|
and called with @racket[#f] when there is a generator, but the generator
|
||||||
ended up returning @racket[contract-random-generate-fail].
|
ended up returning @racket[contract-random-generate-fail].
|
||||||
|
|
||||||
|
@examples[#:eval (contract-eval) #:once
|
||||||
|
(for/list ([i (in-range 10)])
|
||||||
|
(contract-random-generate (or/c integer? #f)))]
|
||||||
|
|
||||||
@history[#:changed "6.1.1.5" @list{Allow @racket[fail] to accept a boolean.}]
|
@history[#:changed "6.1.1.5" @list{Allow @racket[fail] to accept a boolean.}]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3220,6 +3224,20 @@ ended up returning @racket[contract-random-generate-fail].
|
||||||
contract and, for those that do, uses information about the contract's shape
|
contract and, for those that do, uses information about the contract's shape
|
||||||
to poke and prod at the value. For example, if the value is function, it will
|
to poke and prod at the value. For example, if the value is function, it will
|
||||||
use the contract to tell it what arguments to supply to the value.
|
use the contract to tell it what arguments to supply to the value.
|
||||||
|
|
||||||
|
@examples[#:eval (contract-eval) #:once
|
||||||
|
(define/contract (returns-false x)
|
||||||
|
(-> integer? integer?)
|
||||||
|
(code:comment "does not obey its contract")
|
||||||
|
#f)
|
||||||
|
(eval:error (contract-exercise returns-false))
|
||||||
|
|
||||||
|
(define/contract (calls-its-argument-with-eleven f)
|
||||||
|
(-> (-> integer? integer?) boolean?)
|
||||||
|
(code:comment "f returns an integer, but")
|
||||||
|
(code:comment "we're supposed to return a boolean")
|
||||||
|
(f 11))
|
||||||
|
(eval:error (contract-exercise calls-its-argument-with-eleven))]
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(contract-random-generate/choose [c contract?] [fuel exact-nonnegative-integer?])
|
@defproc[(contract-random-generate/choose [c contract?] [fuel exact-nonnegative-integer?])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user