8 Contracts
(require (planet cce/scheme:7:3/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 | |||
self-contract violation: expected <boolean?>, given: 'cat | |||
contract on predicates from (definition predicates), | |||
blaming (definition predicates) | |||
contract: | |||
(sequence/c (-> any/c boolean?)) | |||
at: eval:2.0 |
Examples: | |||
| |||
> (dict-ref table 'A) | |||
"A" | |||
> (dict-ref table 'B) | |||
self-contract violation: expected <string?>, given: 2 | |||
contract on table from (definition table), blaming | |||
(definition table) | |||
contract: (dict/c symbol? string?) | |||
at: eval:2.0 | |||
> (dict-ref table 3) | |||
self-contract violation: expected <symbol?>, given: 3 | |||
contract on table from (definition table), blaming | |||
(definition table) | |||
contract: (dict/c symbol? string?) | |||
at: eval:2.0 |
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.