2 Utilities for Contracts
(require lathe-comforts/contract) | |
package: lathe-comforts-lib |
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 pat body-expr)
body-expr : contract?
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