7.6 Contract Utilities
(guilty-party exn) → any |
exn : exn? |
(flat-contract? v) → boolean? |
v : any/c |
For example, flat-contract constructs flat contracts from predicates, and symbols, booleans, numbers, and other ordinary Scheme values (that are defined as contracts) are also flat contracts.
(flat-contract-predicate v) → (any/c . -> . any/c) |
v : flat-contract? |
(contract-first-order-passes? contract v) → boolean? |
contract : contract? |
v : any/c |
If it returns #f, the contract is guaranteed not to hold for that value; if it returns #t, the contract may or may not hold. If the contract is a first-order contract, a result of #t guarantees that the contract holds.
(make-none/c sexp-name) → contract? |
sexp-name : any/c |
(contract-violation->string) |
→ (-> any/c any/c (or/c #f any/c) any/c string? string?) |
(contract-violation->string proc) → void? |
proc : (-> any/c any/c (or/c #f any/c) any/c string? string?) |
the value that the contract applies to,
a syntax object representing the source location where the contract was established,
the name of the party that violated the contract (#f indicates that the party is not known, not that the party’s name is #f),
an sexpression representing the contract, and
a message indicating the kind of violation.
If the contract was establised via provide/contract, the names of the party to the contract will be sexpression versions of the module paths (as returned by collapse-module-path).
(recursive-contract contract-expr) |
(opt/c contract-expr) |
(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.