diff --git a/collects/mzlib/contract.ss b/collects/mzlib/contract.ss index 185ade7c89..0ecd64b65b 100644 --- a/collects/mzlib/contract.ss +++ b/collects/mzlib/contract.ss @@ -2516,17 +2516,18 @@ add struct contracts for immutable structs? (define-syntax (coerce/select-contract stx) (syntax-case stx () [(_ name val) - (syntax - (let ([x val]) - (cond - [(contract? x) - (contract-proc x)] - [(and (procedure? x) (procedure-arity-includes? x 1)) - (contract-proc (flat-contract x))] - [else - (error 'name - "expected contract or procedure of arity 1, got ~e" - x)])))])) + (syntax (coerce/select-contract/proc 'name val))])) + + (define (coerce/select-contract/proc name x) + (cond + [(contract? x) + (contract-proc x)] + [(and (procedure? x) (procedure-arity-includes? x 1)) + (contract-proc (flat-contract x))] + [else + (error name + "expected contract or procedure of arity 1, got ~e" + x)])) ;; coerce-contract : id (union contract? procedure-arity-1) -> contract ;; contract-proc = sym sym stx -> alpha -> alpha @@ -2535,17 +2536,17 @@ add struct contracts for immutable structs? (define-syntax (coerce-contract stx) (syntax-case stx () [(_ name val) - (syntax - (let ([x val]) - (cond - [(contract? x) x] - [(and (procedure? x) (procedure-arity-includes? x 1)) - (flat-contract x)] - [else - (error 'name - "expected contract or procedure of arity 1, got ~e" - x)])))])) + (syntax (coerce-contract/proc 'name val))])) + (define (coerce-contract/proc name x) + (cond + [(contract? x) x] + [(and (procedure? x) (procedure-arity-includes? x 1)) + (flat-contract x)] + [else + (error name + "expected contract or procedure of arity 1, got ~e" + x)])) ; ; diff --git a/collects/mzlib/match.ss b/collects/mzlib/match.ss index 17f2d9cf85..6142238779 100644 --- a/collects/mzlib/match.ss +++ b/collects/mzlib/match.ss @@ -130,15 +130,16 @@ exn:misc:match-value define-match-expander) + ;; FIXME: match-helper and match-error should each be split + ;; into a compile-time part and a run-time part. + (require-for-syntax "private/convert-pat.ss" "private/match-helper.ss") - (require-for-template mzscheme (prefix plt: "private/match-internal-func.ss")) - (require (prefix plt: "private/match-internal-func.ss") - "private/match-expander.ss" - "private/match-helper.ss" - "private/match-error.ss") + "private/match-expander.ss" + "private/match-helper.ss" + "private/match-error.ss") (define-syntax (match-lambda stx) (syntax-case stx () diff --git a/collects/mzlib/plt-match.ss b/collects/mzlib/plt-match.ss index 9d069aa0a9..c733ac1a44 100644 --- a/collects/mzlib/plt-match.ss +++ b/collects/mzlib/plt-match.ss @@ -138,7 +138,6 @@ match-let* match-letrec match-define - match:test-no-order pregexp-match-with-error exn:misc:match? exn:misc:match-value @@ -148,8 +147,7 @@ (require "private/match-internal-func.ss" "private/match-expander.ss" "private/match-helper.ss" - "private/match-error.ss" - "private/render-helpers.ss") + "private/match-error.ss") ) diff --git a/collects/mzlib/private/convert-pat.ss b/collects/mzlib/private/convert-pat.ss index 590b473733..14de311ad7 100644 --- a/collects/mzlib/private/convert-pat.ss +++ b/collects/mzlib/private/convert-pat.ss @@ -3,13 +3,10 @@ "match-helper.ss" "match-expander-struct.ss") - (require-for-template - mzscheme - "match-error.ss" - "match-helper.ss") + (require-for-template mzscheme + "match-error.ss") - (provide convert-pat handle-clauses convert-pats) - + (provide convert-pat handle-clauses convert-pats) ;; these functions convert the patterns from the old syntax ;; to the new syntax diff --git a/collects/mzlib/private/coupling-and-binding.scm b/collects/mzlib/private/coupling-and-binding.scm index 5a4161f2e6..056e7a33d3 100644 --- a/collects/mzlib/private/coupling-and-binding.scm +++ b/collects/mzlib/private/coupling-and-binding.scm @@ -7,10 +7,7 @@ (require "test-structure.scm" "match-helper.ss") - (require-for-template - mzscheme - "test-structure.scm" - "match-helper.ss") + (require-for-template mzscheme) ;;!(function couple-tests ;; (form (couple-tests test-list ks-func kf-func let-bound) diff --git a/collects/mzlib/private/emit-assm.scm b/collects/mzlib/private/emit-assm.scm index 7799c95a32..d83c39c050 100644 --- a/collects/mzlib/private/emit-assm.scm +++ b/collects/mzlib/private/emit-assm.scm @@ -6,10 +6,8 @@ (require "match-helper.ss" "coupling-and-binding.scm") - (require-for-template - mzscheme - "match-helper.ss" - "coupling-and-binding.scm") + (require-for-template mzscheme) + ;;!(function emit ;; (form (emit act-test-func ae let-bound sf bv kf ks) ;; -> diff --git a/collects/mzlib/private/gen-match.ss b/collects/mzlib/private/gen-match.ss index 931dda4d8b..9c47431ba4 100644 --- a/collects/mzlib/private/gen-match.ss +++ b/collects/mzlib/private/gen-match.ss @@ -14,17 +14,9 @@ "tag-negate-tests.scm" "convert-pat.ss") - (require-for-template - mzscheme - (lib "etc.ss") - (lib "stx.ss" "syntax") - "match-error.ss" - "coupling-and-binding.scm" - "update-counts.scm" - "update-binding-counts.scm" - "render-test-list.scm" - "reorder-tests.scm" - "tag-negate-tests.scm") + (require-for-template mzscheme + (lib "etc.ss") + "match-error.ss") ;;!(function mark-patlist ;; (form (mark-patlist clauses) -> marked-clause-list) diff --git a/collects/mzlib/private/getter-setter.scm b/collects/mzlib/private/getter-setter.scm index eebdd97bdf..a2a70a6219 100644 --- a/collects/mzlib/private/getter-setter.scm +++ b/collects/mzlib/private/getter-setter.scm @@ -6,12 +6,8 @@ "match-helper.ss" "match-error.ss" (lib "stx.ss" "syntax")) - (require-for-template - mzscheme - "coupling-and-binding.scm" - "match-helper.ss" - "match-error.ss" - (lib "stx.ss" "syntax")) + (require-for-template mzscheme + "match-error.ss") ;;!(function setter ;; (form (setter e ident let-bound) -> syntax) diff --git a/collects/mzlib/private/match-expander.ss b/collects/mzlib/private/match-expander.ss index d908c8ecc9..dbe7011be1 100644 --- a/collects/mzlib/private/match-expander.ss +++ b/collects/mzlib/private/match-expander.ss @@ -1,8 +1,5 @@ (module match-expander mzscheme (provide (all-defined)) - ;(require "match-expander-struct.ss") - (require-for-template "match-expander-struct.ss" - "match-error.ss") (require-for-syntax "match-expander-struct.ss" "match-error.ss") diff --git a/collects/mzlib/private/match-helper.ss b/collects/mzlib/private/match-helper.ss index f1374bdd13..6e7c721851 100644 --- a/collects/mzlib/private/match-helper.ss +++ b/collects/mzlib/private/match-helper.ss @@ -8,9 +8,7 @@ "match-error.ss" (lib "list.ss")) - (require-for-template mzscheme - (lib "struct.ss" "syntax") - (lib "syntax-utils.ss" "mzlib" "private")) + (require-for-template mzscheme) ;; define a syntax-transformer in terms of a two-argument function (define-syntax define-proc diff --git a/collects/mzlib/private/match-internal-func.ss b/collects/mzlib/private/match-internal-func.ss index 7672eb74e5..08fbfb40f9 100644 --- a/collects/mzlib/private/match-internal-func.ss +++ b/collects/mzlib/private/match-internal-func.ss @@ -4,20 +4,12 @@ (require-for-syntax "gen-match.ss" "match-helper.ss" - "match-error.ss" - #;"convert-pat.ss") - - (require-for-template "gen-match.ss" - "match-helper.ss" - mzscheme) + "match-error.ss") (require (lib "etc.ss") (lib "list.ss") - "gen-match.ss" "match-expander.ss" - "match-helper.ss" - "match-error.ss" - "render-helpers.ss") + "match-error.ss") (define-syntax (match stx) diff --git a/collects/mzlib/private/parse-quasi.scm b/collects/mzlib/private/parse-quasi.scm index 80902b765e..964ac0eb2e 100644 --- a/collects/mzlib/private/parse-quasi.scm +++ b/collects/mzlib/private/parse-quasi.scm @@ -7,10 +7,7 @@ (lib "stx.ss" "syntax")) (require-for-template mzscheme - "match-error.ss" - "match-helper.ss" - (lib "etc.ss") - (lib "stx.ss" "syntax")) + "match-error.ss") ;; Raise an error from a quasi-pattern (define q-error diff --git a/collects/mzlib/private/render-helpers.ss b/collects/mzlib/private/render-helpers.ss index c75488c385..982968d0a3 100644 --- a/collects/mzlib/private/render-helpers.ss +++ b/collects/mzlib/private/render-helpers.ss @@ -10,64 +10,14 @@ "parse-quasi.scm" (lib "list.ss")) - (require-for-template - mzscheme - "match-helper.ss" - "match-error.ss" - - "emit-assm.scm" - "getter-setter.scm" - "parse-quasi.scm" - (lib "list.ss")) + (require-for-template mzscheme + (lib "list.ss") + "match-error.ss") (provide (all-from "emit-assm.scm") (all-from "getter-setter.scm") (all-from "parse-quasi.scm")) - ;;!(function match:test-no-order - ;; (form (match:test-no-order tests l last-test ddk-num) - ;; -> - ;; bool) - ;; (contract (list list test integer) -> bool)) - ;; This is a recursive depth first search for a sequence of - ;; items in list l which will satisfy all of the tests in list - ;; tests. This is used for list-no-order and hash-table patterns. - ;; This function also handles ddk patterns by passing it the last - ;; test before the ddk and the value of k. - (define (match:test-no-order tests l last-test ddk-num) - (define (handle-last-test test l) - (and (>= (length l) ddk-num) - (andmap test l))) - (define (dep-first-test head rest tests) - (cond ((null? tests) - (if last-test - (handle-last-test last-test (cons head rest)) - #f)) - ((null? rest) - (if last-test - (and (= 0 ddk-num) - (= 1 (length tests)) - ((car tests) head)) - (and (= 1 (length tests)) - ((car tests) head)))) - (else (and (pair? tests) - ((car tests) head) - (match:test-no-order (cdr tests) - rest - last-test - ddk-num))))) - ; I think this is equivalent to - #;(ormap (lambda (elem) - (dep-first-test elem - (remove elem l) - tests)) - l) - (let loop ((lst l)) - (if (null? lst) - #f - (or (dep-first-test (car lst) (remove (car lst) l) tests) - (loop (cdr lst)))))) - (define (append-if-necc sym stx) (syntax-case stx () (() (syntax (list))) diff --git a/collects/mzlib/private/render-test-list.scm b/collects/mzlib/private/render-test-list.scm index 2e4c0fa9ee..62240df115 100644 --- a/collects/mzlib/private/render-test-list.scm +++ b/collects/mzlib/private/render-test-list.scm @@ -21,19 +21,9 @@ (require-for-syntax "match-helper.ss" "match-expander-struct.ss") - (require-for-template - mzscheme - "match-expander-struct.ss" - "match-error.ss" - "match-helper.ss" - "test-structure.scm" - "coupling-and-binding.scm" - "update-counts.scm" - "update-binding-counts.scm" - "reorder-tests.scm" - - ;; the following are only used by render-test-list - "render-helpers.ss") + (require-for-template mzscheme + "match-error.ss" + "test-no-order.ss") ;; BEGIN SPECIAL-GENERATORS.SCM diff --git a/collects/mzlib/private/reorder-tests.scm b/collects/mzlib/private/reorder-tests.scm index 36f8dfd1b0..cae052673e 100644 --- a/collects/mzlib/private/reorder-tests.scm +++ b/collects/mzlib/private/reorder-tests.scm @@ -6,8 +6,7 @@ (require "test-structure.scm") - (require-for-template mzscheme - "test-structure.scm") + (require-for-template mzscheme) ;; There really ought to be a stable sort in the std library. diff --git a/collects/mzlib/private/tag-negate-tests.scm b/collects/mzlib/private/tag-negate-tests.scm index 45474b287e..5ecbd0b48d 100644 --- a/collects/mzlib/private/tag-negate-tests.scm +++ b/collects/mzlib/private/tag-negate-tests.scm @@ -1,8 +1,6 @@ (module tag-negate-tests mzscheme (provide tag-negate-tests) (require "test-structure.scm") - #;(require-for-template mzscheme - "test-structure.scm") (define (tag-neg-test ls target-set) (easy-tag ls #f target-set)) diff --git a/collects/mzlib/private/test-no-order.ss b/collects/mzlib/private/test-no-order.ss new file mode 100644 index 0000000000..ec3e5a4eee --- /dev/null +++ b/collects/mzlib/private/test-no-order.ss @@ -0,0 +1,48 @@ +(module test-no-order mzscheme + (require (lib "list.ss")) + + (provide match:test-no-order) + + ;;!(function match:test-no-order + ;; (form (match:test-no-order tests l last-test ddk-num) + ;; -> + ;; bool) + ;; (contract (list list test integer) -> bool)) + ;; This is a recursive depth first search for a sequence of + ;; items in list l which will satisfy all of the tests in list + ;; tests. This is used for list-no-order and hash-table patterns. + ;; This function also handles ddk patterns by passing it the last + ;; test before the ddk and the value of k. + (define (match:test-no-order tests l last-test ddk-num) + (define (handle-last-test test l) + (and (>= (length l) ddk-num) + (andmap test l))) + (define (dep-first-test head rest tests) + (cond ((null? tests) + (if last-test + (handle-last-test last-test (cons head rest)) + #f)) + ((null? rest) + (if last-test + (and (= 0 ddk-num) + (= 1 (length tests)) + ((car tests) head)) + (and (= 1 (length tests)) + ((car tests) head)))) + (else (and (pair? tests) + ((car tests) head) + (match:test-no-order (cdr tests) + rest + last-test + ddk-num))))) + ; I think this is equivalent to + #;(ormap (lambda (elem) + (dep-first-test elem + (remove elem l) + tests)) + l) + (let loop ((lst l)) + (if (null? lst) + #f + (or (dep-first-test (car lst) (remove (car lst) l) tests) + (loop (cdr lst))))))) diff --git a/collects/mzlib/private/update-binding-counts.scm b/collects/mzlib/private/update-binding-counts.scm index 64f8a91265..f3e73678eb 100644 --- a/collects/mzlib/private/update-binding-counts.scm +++ b/collects/mzlib/private/update-binding-counts.scm @@ -3,7 +3,6 @@ (provide update-binding-counts update-binding-count) (require "test-structure.scm") - (require-for-template "test-structure.scm") (require (lib "etc.ss")) diff --git a/collects/mzlib/private/update-counts.scm b/collects/mzlib/private/update-counts.scm index 7a6a64ce55..724d42e18f 100644 --- a/collects/mzlib/private/update-counts.scm +++ b/collects/mzlib/private/update-counts.scm @@ -7,9 +7,6 @@ (require "test-structure.scm" "match-helper.ss") - #;(require-for-template "test-structure.scm" - "match-helper.ss") - ;;!(function test-filter ;; (form (test-filter test-list) -> test-list) ;; (contract list -> list))