On this page:
poly/ c
apply/ c
memory/ c
Version: 4.2.3

11 Anaphoric Contracts

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

 (require unstable/poly-c)

(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.