diff --git a/collects/mzlib/contract.ss b/collects/mzlib/contract.ss index 9f69097e62..373846be04 100644 --- a/collects/mzlib/contract.ss +++ b/collects/mzlib/contract.ss @@ -34,10 +34,14 @@ lazy-depth-to-look) (except-out (all-from-out scheme/private/contract) + old-define/contract + define/contract + with-contract check-between/c string-len/c check-unary-between/c) - (rename-out [string-len/c string/len])) + (rename-out [string-len/c string/len] + [old-define/contract define/contract])) ;; from contract-guts.ss diff --git a/collects/scheme/contract.ss b/collects/scheme/contract.ss index ca55dbf472..617fd07c81 100644 --- a/collects/scheme/contract.ss +++ b/collects/scheme/contract.ss @@ -27,6 +27,7 @@ differences from v3: check-procedure check-procedure/more) (except-out (all-from-out "private/contract.ss") + old-define/contract check-between/c check-unary-between/c)) diff --git a/collects/scheme/private/contract.ss b/collects/scheme/private/contract.ss index 000b3191fc..c1ce86a3d1 100644 --- a/collects/scheme/private/contract.ss +++ b/collects/scheme/private/contract.ss @@ -12,6 +12,7 @@ improve method arity mismatch contract violation error messages? (provide (rename-out [-contract contract]) recursive-contract provide/contract + old-define/contract define/contract with-contract current-contract-region) @@ -57,7 +58,9 @@ improve method arity mismatch contract violation error messages? #,(syntax-position id) #,(syntax-span id)) #,(format "~s" (syntax->datum id)))) - + + + ; ; ; @@ -75,6 +78,68 @@ improve method arity mismatch contract violation error messages? ; ; ; +;; First, we have the old define/contract implementation, which +;; is still used in mzlib/contract. + +(define-for-syntax (old-make-define/contract-transformer contract-id id) + (make-set!-transformer + (λ (stx) + (with-syntax ([neg-blame-str (a:build-src-loc-string stx)] + [contract-id contract-id] + [id id]) + (syntax-case stx (set!) + [(set! id arg) + (raise-syntax-error 'define/contract + "cannot set! a define/contract variable" + stx + (syntax id))] + [(f arg ...) + (syntax/loc stx + ((-contract contract-id + id + (syntax->datum (quote-syntax f)) + neg-blame-str + (quote-syntax f)) + arg + ...))] + [ident + (identifier? (syntax ident)) + (syntax/loc stx + (-contract contract-id + id + (syntax->datum (quote-syntax ident)) + neg-blame-str + (quote-syntax ident)))]))))) + +;; (define/contract id contract expr) +;; defines `id' with `contract'; initially binding +;; it to the result of `expr'. These variables may not be set!'d. +(define-syntax (old-define/contract define-stx) + (syntax-case define-stx () + [(_ name contract-expr expr) + (identifier? (syntax name)) + (with-syntax ([contract-id + (a:mangle-id define-stx + "define/contract-contract-id" + (syntax name))] + [id (a:mangle-id define-stx + "define/contract-id" + (syntax name))]) + (syntax/loc define-stx + (begin + (define contract-id contract-expr) + (define-syntax name + (old-make-define/contract-transformer (quote-syntax contract-id) + (quote-syntax id))) + (define id (let ([name expr]) name)) ;; let for procedure naming + )))] + [(_ name contract-expr expr) + (raise-syntax-error 'define/contract "expected identifier in first position" + define-stx + (syntax name))])) + + + ;; (define/contract id contract expr) ;; defines `id' with `contract'; initially binding ;; it to the result of `expr'. These variables may not be set!'d.