42 Contracts for struct type properties
(require unstable/prop-contract) |
(struct-type-property/c value-contract) → contract? |
value-contract : contract? |
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) | |||
self-contract violation: expected <number?>, given: 'apple | |||
contract on wrapped from (definition wrapped), blaming | |||
(definition wrapped) | |||
contract: | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
at: eval:3.0 | |||
> (define s2 (s (lambda (n) (if (zero? n) 'zero 'nonzero)))) | |||
> ((get-f s2) 5) | |||
contract violation: expected <number?>, given: 'nonzero | |||
contract on wrapped from (definition wrapped), blaming | |||
top-level | |||
contract: | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
at: eval:3.0 | |||
> ((get-f s2) 'apple) | |||
self-contract violation: expected <number?>, given: 'apple | |||
contract on wrapped from (definition wrapped), blaming | |||
(definition wrapped) | |||
contract: | |||
(struct-type-property/c | |||
(-> any/c (-> number? number?))) | |||
at: eval:3.0 |