Syntax classes and utilities for defining function signatures with contracts, including
an alternative syntax for indy-dependent contracts.
( proc/c argument...optional-rest->result...)
argument = id+ctc
| keywordid+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:
[y(x)(>=/cx)])
[result(xy)(and/cnumber? (>=/c(+ xy)))])
can be written as the following.
Unlike ->i, mandatory and optional arguments are not specified separately.
The contract
(#:y[y(x)(>=/cx)])
[result(xy)(and/cnumber? (>=/c(+ xy)))])
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.
( define/sig (idargument...optional-rest->result...) body...)
argument = id+ctc
| keywordid+ctc
id+ctc = id-or-optional/default
| (id-or-optional:contract-expr)
id-or-optional/default = id
| [iddefault-expr]
optional-rest =
| ..id+ctc
result = (id+ctc)
Defines a procedure with the given signature and applies the corresponding contract.
For example,
is equivalent to the following.
(define/contract(add#:xx#:y[yx])