Skip to content

Instantly share code, notes, and snippets.

@samth
Created August 20, 2014 16:24
Show Gist options
  • Save samth/1e12f9aa6e97536b6e90 to your computer and use it in GitHub Desktop.
Save samth/1e12f9aa6e97536b6e90 to your computer and use it in GitHub Desktop.
#lang racket/base
(define-struct contract-property [ name
first-order
projection
stronger
generate
exercise
val-first-projection
list-contract? ]
#:omit-define-syntaxes)
(define (contract-property-guard prop info)
(unless (contract-property? prop)
(raise
(make-exn:fail:contract
(format "~a: expected a contract property; got: ~e"
'prop:contract
prop)
(current-continuation-marks))))
prop)
(define-values [ prop:contract contract-struct? contract-struct-property ]
(make-struct-type-property 'prop:contract contract-property-guard))
(define-struct chaperone-contract-property [implementation]
#:omit-define-syntaxes)
(define (chaperone-contract-property-guard prop info)
(unless (chaperone-contract-property? prop)
(raise
(make-exn:fail:contract
(format "~a: expected a chaperone contract property; got: ~e"
'prop:chaperone-contract
prop)
(current-continuation-marks))))
prop)
;; We check to make sure the contract projection actually resulted in
;; a chaperone (or chaperone-friendly) version of the value.
(define (chaperone-contract-property->contract-property fc)
(let ([impl (chaperone-contract-property-implementation fc)])
impl))
(define-values [ prop:chaperone-contract
chaperone-contract-struct?
chaperone-contract-struct-property ]
(make-struct-type-property
'prop:chaperone-contract
chaperone-contract-property-guard
(list (cons prop:contract chaperone-contract-property->contract-property))))
(struct p ()
#:property prop:chaperone-contract (make-chaperone-contract-property
(make-contract-property 0 0 values 0 0 0 0 0)))
(define (contract-struct-projection c)
(let* ([prop (contract-struct-property c)]
[get-projection (contract-property-projection prop)]
[projection (get-projection c)])
projection))
(contract-struct-projection (p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment