8 Contracts
(require (planet cce/scheme:7:1/contract)) |
This module provides useful contracts and contract constructors.
8.1 Flat Contracts
8.2 Higher-Order Contracts
The first constrains its output to satisfy boolean?. Use predicate/c in positive position for predicates that guarantee a result of #t or #f.
The second constrains its output to satisfy truth/c. Use predicate-like/c in negative position for predicates passed as arguments that may return arbitrary values as truth values.
The first constrains its output to satisfy boolean?. Use comparison/c in positive position for comparisons that guarantee a result of #t or #f.
The second constrains its output to satisfy truth/c. Use comparison-like/c in negative position for comparisons passed as arguments that may return arbitrary values as truth values.
(sequence/c elem/c ...) → contract? |
elem/c : contract? |
Examples: | |||
| |||
| |||
#f | |||
eval:2.0: (definition predicates) broke the contract | |||
(sequence/c (-> any/c boolean?)) | |||
on predicates; expected <boolean?>, given: 'cat |
Examples: | |||
| |||
> (dict-ref table 'A) | |||
"A" | |||
> (dict-ref table 'B) | |||
eval:2.0: (definition table) broke the contract (dict/c | |||
symbol? string?) on table; expected <string?>, given: 2 | |||
> (dict-ref table 3) | |||
eval:2.0: (definition table) broke the contract (dict/c | |||
symbol? string?) on table; expected <symbol?>, given: 3 |
Warning: Bear in mind that key and value contracts are re-wrapped on every dictionary operation, and dictionaries wrapped in dict/c multiple times will perform the checks as many times for each operation. Especially for immutable dictionaries (which may be passed through a constructor that involves dict/c on each update), contract-wrapped dictionaries may be much less efficient than the original dictionaries.