8.16.0.1
signature
(require signature) | package: signature |
Syntax classes and utilities for defining function signatures with contracts, including an alternative syntax for indy-dependent contracts.
syntax
(proc/c argument ... optional-rest -> result ...)
argument = id+ctc | keyword id+ctc id+ctc = id-or-optional | (id-or-optional : contract-expr) id-or-optional = id | [id] optional-rest =
| .. id+ctc result = (id+ctc)
The proc/c defines an indy-dependent contract like ->i. Unlike ->i,
proc/c does not require contract expressions to declare dependencies on other arguments.
Instead, it infers them automatically using the names of arguments and result values declared
in the signature. Warning: proc/c is not currently as efficient as ->i and has a higher performance overhead.
For example, the contract:
can be written as the following.
Unlike ->i, mandatory and optional arguments are not specified separately.
The contract
can be written as the following.
Like ->i, the contract expressions are not always evaluated in order. If there are optional arguments that are not supplied, then the corresponding variables will be bound to a special value called the-unsupplied-arg value.
syntax
(define/sig (id argument ... optional-rest -> result ...) body ...)
argument = id+ctc | keyword id+ctc id+ctc = id-or-optional/default | (id-or-optional : contract-expr) id-or-optional/default = id | [id default-expr] optional-rest =
| .. id+ctc result = (id+ctc)
Defines a procedure with the given signature and applies the corresponding contract.
For example,
(define/sig (add #:x (x : number?) #:y ([y x] : (>=/c x)) -> (result : (and/c number? (>=/c (+ x y))))) (+ x y))
is equivalent to the following.