4 Contracts
(require unstable/contract) |
This library is unstable; compatibility will not be maintained. See Unstable for more information.
| ||
| ||
| ||
|
(singleton-list? x) → boolean? |
x : any/c |
The subsequent bindings were added by Ryan Culpepper.
(if/c predicate then-contract else-contract) → contract? |
predicate : (-> any/c any/c) |
then-contract : contract? |
else-contract : contract? |
Equivalent to (if/c procedure? (-> any) any/c).
(rename-contract contract name) → contract? |
contract : contract? |
name : any/c |
The resulting contract is a flat contract if contract is a flat contract.
The subsequent bindings were added by Carl Eastlund <cce@racket-lang.org>.
4.1 Flat Contracts
4.2 Syntax Object Contracts
(syntax-datum/c datum/c) → flat-contract? |
datum/c : any/c |
(syntax-listof/c elem/c) → flat-contract? |
elem/c : any/c |
(syntax-list/c elem/c ...) → flat-contract? |
elem/c : any/c |
4.3 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:3.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:4.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:4.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.