2 Utilities for Contracts
(require lathe-comforts/contract) | |
package: lathe-comforts-lib |
procedure
(obstinacy? v) → boolean?
v : any/c
Contract obstinacy can be thought of as a scale with two ends. Impersonator contracts are the most obstinate since they can go to any length to impose behavior on the values that pass through, while flat contracts are the most reticent since they don’t pass any more judgment on a value after they’ve ferried it through.
By default, Racket contracts are usually as obstinate as can be; contract? refers generally to impersonator contracts. Only certain contracts exercise reticence.
syntax
syntax
match expander
procedure
v : any/c
Every two impersonator-obstinacy values are equal?.
syntax
syntax
match expander
procedure
(chaperone-obstinacy? v) → boolean?
v : any/c
Every two chaperone-obstinacy values are equal?.
syntax
syntax
match expander
procedure
(flat-obstinacy? v) → boolean?
v : any/c
Every two flat-obstinacy values are equal?.
procedure
ob : obstinacy?
procedure
ob : obstinacy?
procedure
(obstinacy-get-coerce-contract-for-id ob id) → (-> any/c (obstinacy-contract/c ob)) ob : obstinacy? id : symbol?
If the value to be converted is not one of the coercible values, the coercion procedure signals an error with id in its error message.
procedure
(value-name-for-contract v) → any/c
v : any/c
This can come in handy when composiing relatively large contracts that use the same value in multiple places. It keeps the name more concise than it usually would be.
syntax
(fix/c self-id options ... contract-expr)
(fix/c (self-id [arg-id arg-expr] ...) options ... contract-expr)
contract-expr : contract?
In the unparenthesized case, self-id is bound to a contract. The contract functionality of self-id should be used only after contract-expr has returned a contract, and it behaves just like that contract.
In the parenthesized case, self-id is bound to a contract-returning function that takes one argument for each arg-id. The contract functionality of the result of self-id should be used only after contract-expr has returned a contract, and it works by evaluating contract-expr again with arg-id bound to each function argument.
In both cases, the contract obtained from self-id is delayed so that it can be used without causing an infinite loop. This functionality is based on recursive-contract, and the given options supply the optional arguments of the recursive-contract operation.
> (fix/c simple-s-expression/c (or/c symbol? (listof simple-s-expression/c))) #<contract: (fix/c simple-s-expression/c (or/c symbol? (listof simple-s-expression/c)))>
syntax
(by-own-method/c maybe-obstinacy pat body-expr)
maybe-obstinacy =
| #:obstinacy obstinacy-expr
obstinacy-expr : obstinacy?
body-expr : (obstinacy-contract/c obstinacy-expr)
A contract obstinacy may be given as obstinacy-expr, which defaults to (impersonator-obstinacy). The overall result is a contract of that contract obsinacy (e.g. a chaperone contract if using (chaperone-obstinacy), or any contract at all if using (impersonator-obstinacy)). The result of body-expr must be a contract of that contract obstinacy as well.
The name of the returned contract includes pat and body-expr verbatim. If they contain references to variables defined elsewhere, let/c may be useful to ensure those variable bindings are apparent in the overall contract name.
procedure
(equal/c example) → flat-contract?
example : any/c
procedure
v : any/c