From 76f55ad753c2a56e7fbc4b15efd90500f2880c20 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Mon, 13 Sep 2010 14:39:05 -0600 Subject: [PATCH] docs for unstable/prop-contract --- .../unstable/scribblings/prop-contract.scrbl | 52 +++++++++++++++++++ collects/unstable/scribblings/unstable.scrbl | 1 + 2 files changed, 53 insertions(+) create mode 100644 collects/unstable/scribblings/prop-contract.scrbl diff --git a/collects/unstable/scribblings/prop-contract.scrbl b/collects/unstable/scribblings/prop-contract.scrbl new file mode 100644 index 0000000000..16e83dbf05 --- /dev/null +++ b/collects/unstable/scribblings/prop-contract.scrbl @@ -0,0 +1,52 @@ +#lang scribble/manual +@(require scribble/struct + scribble/decode + scribble/eval + "utils.rkt" + (for-label racket/base + racket/contract + unstable/prop-contract)) + +@(define the-eval (make-base-eval)) +@(the-eval '(require racket/contract unstable/prop-contract)) + +@title{Contracts for struct type properties} + +@defmodule[unstable/prop-contract] + +@unstable[@author+email["Ryan Culpepper" "ryanc@racket-lang.org"]] + +@defproc[(struct-type-property/c [value-contract contract?]) + contract?]{ + +Produces a contract for struct type properties. When the contract is +applied to a struct type property, it produces a wrapped struct type +property. When the wrapped struct type property is used to create a +new struct type (via @racket[struct], @racket[make-struct-type], etc), +it applies @racket[value-contract] to the value associated with the +property. + +The contract has no effect on the struct type property accessor. + +@examples[#:eval the-eval +(define-values (prop prop? prop-ref) + (make-struct-type-property 'prop)) + +(define/contract wrapped + (struct-type-property/c (-> any/c (-> number? number?))) + prop) + +(struct s (f) + #:property wrapped (lambda (s) (s-f s))) + +(define (get-f s) ((prop-ref s) s)) + +(define s1 (s add1)) +((get-f s1) 5) +((get-f s1) 'apple) + +(define s2 (s (lambda (n) (if (zero? n) 'zero 'nonzero)))) +((get-f s2) 5) +((get-f s2) 'apple) +] +} diff --git a/collects/unstable/scribblings/unstable.scrbl b/collects/unstable/scribblings/unstable.scrbl index 1520a5aa29..fb168bb258 100644 --- a/collects/unstable/scribblings/unstable.scrbl +++ b/collects/unstable/scribblings/unstable.scrbl @@ -111,6 +111,7 @@ Keep documentation and tests up to date. @include-section["markparam.scrbl"] @include-section["debug.scrbl"] @include-section["wrapc.scrbl"] +@include-section["prop-contract.scrbl"] @;{--------}