7.8 Contract Utilities
procedure
(chaperone-contract? v) → boolean?
v : any/c
procedure
v : any/c
procedure
(flat-contract? v) → boolean?
v : any/c
For example, flat-contract constructs flat contracts from predicates, and symbols, booleans, numbers, and other ordinary Racket values (that are defined as contracts) are also flat contracts.
procedure
(flat-contract-predicate v) → (any/c . -> . any/c)
v : flat-contract?
procedure
(contract-name c) → any/c
c : contract?
procedure
(value-contract v) → contract?
v : has-contract?
To support value-contract and has-contract? in your own contract combinators, use prop:contracted or impersonator-prop:contracted.
procedure
(has-contract? v) → boolean?
v : any/c
See also value-contract.
procedure
(make-none/c sexp-name) → contract?
sexp-name : any/c
syntax
(recursive-contract contract-expr)
(recursive-contract contract-expr type)
syntax
(opt/c contract-expr)
syntax
(define-opt/c (id id ...) expr)
For example,
(define-contract-struct bt (val left right)) (define-opt/c (bst-between/c lo hi) (or/c null? (bt/c [val (real-in lo hi)] [left (val) (bst-between/c lo val)] [right (val) (bst-between/c val hi)]))) (define bst/c (bst-between/c -inf.0 +inf.0))
defines the bst/c contract that checks the binary search tree invariant. Removing the -opt/c also makes a binary search tree contract, but one that is (approximately) 20 times slower.