7.6 Contract Utilities
Extracts the name of the guilty party from an exception
raised by the contract system.
Returns #t if its argument is a contract (i.e., constructed
with one of the combinators described in this section or a value that
can be used as a contract) and #f otherwise.
Returns #t when its argument is a contract that can be
checked immediately (unlike, say, a function contract).
flat-contract constructs flat contracts from predicates, and
symbols, booleans, numbers, and other ordinary Scheme values
(that are defined as contracts) are also
Extracts the predicate from a flat contract.
Returns a boolean indicating if the first-order tests
of contract pass for v.
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
Makes a contract that accepts no values, and reports the
name sexp-name when signaling a contract violation.
This is a parameter that is used when constructing a
contract violation error. Its value is procedure that
accepts five arguments:
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.
The procedure then
returns a string that is put into the contract error
message. Note that the value is often already included in
the message that indicates the 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).
Delays the evaluation of its argument until the contract is checked,
making recursive contracts possible.
This optimizes its argument contract expression by
traversing its syntax and, for known contract combinators,
fuses them into a single contract combinator that avoids as
much allocation overhad as possible. The result is a
contract that should behave identically to its argument,
except faster (due to the less allocation).
This defines a recursive contract and simultaneously
optimizes it. Semantically, it behaves just as if
were not present, defining a function on
contracts (except that the body expression must return a
contract). But, it also optimizes that contract definition,
avoiding extra allocation, much like opt/c
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.