8.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
(list-contract? v) → boolean?
v : any/c
A list contract is one that insists that its argument is a list?, meaning that the value cannot be cyclic and must either be the empty list or a pair constructed with cons and another list.
Added in version 6.0.1.13 of package base.
procedure
(contract-name c) → any/c
c : contract?
procedure
(value-contract v) → contract?
v : has-contract?
To support value-contract and value-contract in your own contract combinators, use prop:contracted or impersonator-prop:contracted.
procedure
(has-contract? v) → boolean?
v : any/c
procedure
(value-blame v) → (or/c blame? #f)
v : has-blame?
To support value-contract and value-blame in your own contract combinators, use prop:blame or impersonator-prop:blame.
Added in version 6.0.1.12 of package base.
procedure
(has-blame? v) → boolean?
v : any/c
Added in version 6.0.1.12 of package base.
procedure
(make-none/c sexp-name) → contract?
sexp-name : any/c
syntax
(recursive-contract contract-expr)
(recursive-contract contract-expr #:list-contract?) (recursive-contract contract-expr type) (recursive-contract contract-expr type #:list-contract?)
If #:list-contract? is returned, then the result is a list-contract? and the contract-expr must evaluate to a list-contract?.
Changed in version 6.0.1.13 of package base: Added the #:list-contract? argument.
syntax
(opt/c contract-expr maybe-name)
maybe-name =
| #:error-name id
If the #:error-name argument is present, and contract-expr evaluates to a non-contract expression, then opt/c raises an error using id as the name of the primitive, instead of using the name opt/c.
Examples: | ||||||||||||||
|
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.