diff --git a/collects/scribblings/guide/contracts-examples.scrbl b/collects/scribblings/guide/contracts-examples.scrbl index 65b6b9255b..8ea1d826e5 100644 --- a/collects/scribblings/guide/contracts-examples.scrbl +++ b/collects/scribblings/guide/contracts-examples.scrbl @@ -63,3 +63,23 @@ Note: To mimic Mitchell and McKim's informal notion of parametericity places, this use of first-class contracts improves on Mitchell and McKim's design (see comments in interfaces). +@; @external-file[1] + +@section{A Customer Manager Component for Managing Customer Relationships} +@begin[ +#reader scribble/comment-reader +[schememod +scheme +;; data definitions + +(define id? symbol?) +(define id-equal? eq?) +(define-struct basic-customer (id name address) #:mutable) + +;; interface +(provide/contract + [id? (-> any/c boolean?)] + [id-equal? (-> id? id? boolean?)] + [struct basic-customer ((id id?) (name string?) (address string?))]) +;; end of interface +]] \ No newline at end of file diff --git a/collects/scribblings/guide/contracts-examples/1.ss b/collects/scribblings/guide/contracts-examples/1.ss index edc63d0ded..09e1519c2e 100644 --- a/collects/scribblings/guide/contracts-examples/1.ss +++ b/collects/scribblings/guide/contracts-examples/1.ss @@ -2,7 +2,7 @@ ;; --- common data definitions ------------------------------------------------ -#lang scheme +; #lang scheme ;; data definitions diff --git a/collects/scribblings/guide/contracts-utils.ss b/collects/scribblings/guide/contracts-utils.ss index 679857e373..e0cb5689fe 100644 --- a/collects/scribblings/guide/contracts-utils.ss +++ b/collects/scribblings/guide/contracts-utils.ss @@ -1,11 +1,14 @@ -#lang scheme/base +#lang scheme + (require scribble/basic - scribble/manual) + (for-syntax scheme/port) + (except-in scribble/manual link)) (provide ctc-section ctc-link exercise - solution) + solution + external-file) (define (ctc-section #:tag [tag #f] . rest) (keyword-apply section @@ -25,3 +28,19 @@ (define (solution) (bold (format "Solution to exercise ~a" exercise-number))) +(define-syntax (external-file stx) + (syntax-case stx () + [(_ filename) + (call-with-input-file (build-path "contracts-examples" (format "~a.ss" (syntax-e #'filename))) + (λ (port) + (define prefix "#reader scribble/comment-reader\n[schememod\nscheme\n") + (define suffix "]") + (with-syntax ([s (parameterize ([read-accept-reader #t]) + (read-syntax 'contract-examples + (input-port-append #f + (open-input-string prefix) + port + (open-input-string suffix))))]) + #'s)))])) + +;(external-file 1) \ No newline at end of file