From dbe366c6a0855abc117d7be2f160be058b882ec8 Mon Sep 17 00:00:00 2001 From: Stevie Strickland Date: Thu, 15 Jan 2009 00:42:49 +0000 Subject: [PATCH] Add error checking for contracted form, also added documentation in reference svn: r13135 --- collects/mzlib/private/unit-keywords.ss | 4 +++- collects/mzlib/unit.ss | 9 ++++++++- collects/scribblings/reference/units.scrbl | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/collects/mzlib/private/unit-keywords.ss b/collects/mzlib/private/unit-keywords.ss index 7e02597836..8533365e9d 100644 --- a/collects/mzlib/private/unit-keywords.ss +++ b/collects/mzlib/private/unit-keywords.ss @@ -3,7 +3,7 @@ (provide only except prefix rename tag import export init-depend link - extends) + extends contracted) (define-syntax-rule (define-syntax-for-error name message) (define-syntax name @@ -34,3 +34,5 @@ "misuse of compound-unit keyword") (define-syntax-for-error extends "misuse of define-signature keyword") +(define-syntax-for-error contracted + "misuse of define-signature keyword") \ No newline at end of file diff --git a/collects/mzlib/unit.ss b/collects/mzlib/unit.ss index ddbd135470..6b2af64412 100644 --- a/collects/mzlib/unit.ss +++ b/collects/mzlib/unit.ss @@ -17,7 +17,7 @@ (provide define-signature-form struct open define-signature provide-signature-elements - only except rename import export prefix link tag init-depend extends + only except rename import export prefix link tag init-depend extends contracted unit? (rename :unit unit) define-unit compound-unit define-compound-unit compound-unit/infer define-compound-unit/infer @@ -252,6 +252,13 @@ val-defs stx-defs (append (syntax->list #'(z ...)) ctcs))) + ((x . z) + (and (identifier? #'x) + (module-identifier=? #'x #'contracted)) + (raise-syntax-error + 'define-signature + "expected a list of [id contract] pairs after the contracted keyword" + (car sig-exprs))) ((x . y) (and (identifier? #'x) (or (module-identifier=? #'x #'define-values) diff --git a/collects/scribblings/reference/units.scrbl b/collects/scribblings/reference/units.scrbl index cb0ee2376a..a37eddce0d 100644 --- a/collects/scribblings/reference/units.scrbl +++ b/collects/scribblings/reference/units.scrbl @@ -160,6 +160,7 @@ the corresponding import. Each @scheme[tagged-sig-id] in an [sig-elem id + (contracted [id contract] ...) (define-syntaxes (id ...) expr) (define-values (value-id ...) expr) (open sig-spec) @@ -175,6 +176,15 @@ of bindings for import or export: @scheme[id]. That is, @scheme[id] is available for use in units importing the signature, and @scheme[id] must be defined by units exporting the signature.} + + @item{Each @scheme[contracted] form in a signature declaration means + that a unit exporting the signature must supply a variable definition + for each @scheme[id] in that form. If the signature is imported, then + uses of @scheme[id] inside the unit are protected by the appropriate + contracts using the unit as the negative blame. If the signature is + exported, then the exported values are protected by the appropriate + contracts which use the unit as the positive blame, but internal uses + of the exported identifiers are not protected.} @item{Each @scheme[define-syntaxes] form in a signature declaration introduces a macro to that is available for use in any unit that