▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Contracts
4 | Exceptions
5 | Lists
6 | Net
7 | Path
8 | Source Locations
9 | Strings
10 | Structs
11 | Syntax
12 | Anaphoric Contracts
13 | Finding Mutated Variables
14 | Find
15 | Interface-Oriented Programming for Classes
16 | Sequences
17 | Hash Tables
18 | Match
19 | Skip Lists
20 | Interval Maps
21 | GUI libraries

On this page:

poly/ c
apply/ c
memory/ c

Version: 4.2.4
top← prev up next →

### 12`` Anaphoric Contracts

Sam Tobin-Hochstadt <samth@ccs.neu.edu>
and Carl Eastlund <cce@ccs.neu.edu>

(require unstable/poly-c)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

(poly/c ([id+ id-] ...) cnt)

Creates an “anaphoric” contract, using the id+ ... as the positive positions, and the id- ... as the negative positions.

Anaphoric contracts verify that only values provided to a given positive position flow out of the corresponding negative position.

Examples:

> (define/contract (f x) (poly/c ([in out]) (in . -> . out))
(if (equal? x 17) 18 x))

> (f 1)
1
> (f #f)
#f
> (f 17)

(function f) broke the contract
(poly/c ((in out)) (->

in out))
on f; expected <out>, given: 18

(apply/c cnt [#:name name]) → contract?
cnt : any/c
name : any/c = (build-compound-type-name 'apply/c c)

Produces a procedure contract that is like cnt, but any delayed evalutation in cnt is re-done on every application of the contracted function.

(memory/c | [ | #:name name |  |  |  |
|  | #:from from |  |  |  |
|  | #:to to |  |  |  |
|  | #:weak weak? |  |  |  |
|  | #:equal equal |  |  |  |

#:table make-table])

→

flat-contract? |  | flat-contract?

name : any/c = "memory/c"
from : any/c = (format "~a:from" name)
to : any/c = (format "~a:to" name)
weak? : any/c = #t
equal : (or/c 'eq 'eqv 'equal) = 'eq

| make-table |  | : |  | (-> hash?)

=

(case equal
[(eq) (if weak? make-weak-hasheq make-hasheq)]
[(eqv) (if weak? make-weak-hasheqv make-hasheqv)]
[(equal) (if weak? make-weak-hash make-hash)])

Produces a pair of contracts. The first contract remembers all values that flow into it, and rejects nothing. The second accepts only values that have previously been passed to the first contract.

If weak? is not #f, the first contract holds onto the values only weakly. from and to are the names of the of the two contracts.

top← prev up next →