This library is experimental; compatibility may not be maintained.
This package implements contract parameters that allow for dynamically bound contracts. Contract parameters can be used to implement checks that are similar to computational contracts [Scholliers et al. 2013].
Suppose you want a contract that prevents
calling a certain family of functions—
First, create a contract parameter called prohibitable/c. What it checks depends on the context. By default, it checks any/c.
Next, define a prohibit/c contract that will instantiate the prohibitable/c parameter with none/c. Thus, if you attach prohibit/c to a function, then during that function’s execution prohibitable/c will be bound to none/c.
Using prohibitable/c in a function contract will allow you to prohibit it. In this case, we can check that will-prevent will never be called.
(define/contract (will-prevent x) (-> (and/c integer? prohibitable/c) any) (add1 x)) (define/contract (good-prohibit) prohibit/c 43) (define/contract (bad-prohibit) prohibit/c (will-prevent 42))
Here’s what it looks like if you try to call good-prohibit and bad-prohibit:
will-prevent: contract violation;
none/c allows no values
in: the 2nd conjunct of
the 1st argument of
(-> (and/c integer? ???) any)
contract from: (function will-prevent)
(assuming the contract is correct)
(parameterize/c [parameter expr] ...+)