Version: 5.0.2
42 Contracts for struct type properties
(require unstable/prop-contract) |
This library is unstable;
compatibility will not be maintained.
See Unstable for more information.
(struct-type-property/c value-contract) → contract? |
value-contract : contract? |
Produces a contract for struct type properties. When the contract is
applied to a struct type property, it produces a wrapped struct type
property. When the wrapped struct type property is used to create a
new struct type (via struct, make-struct-type, etc),
it applies value-contract to the value associated with the
property.
The contract has no effect on the struct type property accessor.
Examples: | |||
| |||
| |||
| |||
> (define (get-f s) ((prop-ref s) s)) | |||
> (define s1 (s add1)) | |||
> ((get-f s1) 5) | |||
6 | |||
> ((get-f s1) 'apple) | |||
eval:3.0: (definition wrapped) broke the contract | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
on wrapped; expected <number?>, given: 'apple | |||
> (define s2 (s (lambda (n) (if (zero? n) 'zero 'nonzero)))) | |||
> ((get-f s2) 5) | |||
eval:3.0: top-level broke the contract | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
on wrapped; expected <number?>, given: 'nonzero | |||
> ((get-f s2) 'apple) | |||
eval:3.0: (definition wrapped) broke the contract | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
on wrapped; expected <number?>, given: 'apple |