diff --git a/collects/scheme/match/define-forms.ss b/collects/scheme/match/define-forms.ss index caa92b6335..7ab16fdae2 100644 --- a/collects/scheme/match/define-forms.ss +++ b/collects/scheme/match/define-forms.ss @@ -20,8 +20,14 @@ [(_ es . clauses) (go parse-id stx #'es #'clauses (syntax-local-certifier))])) - (define-syntax-rule (match arg [p . es] ...) - (match* (arg) [(p) . es] ...)) + (define-syntax (match stx) + (syntax-case stx () + [(match arg cl ...) + (with-syntax ([clauses + (for/list ([c (syntax->list #'(cl ...))]) + (syntax-case c () + [[p . es] (syntax/loc c [(p) . es])]))]) + (syntax/loc stx (match* (arg) . clauses)))])) (define-syntax (match-lambda stx) (syntax-case stx () diff --git a/collects/scheme/match/gen-match.ss b/collects/scheme/match/gen-match.ss index 6dfdc2a4f0..01b945e53b 100644 --- a/collects/scheme/match/gen-match.ss +++ b/collects/scheme/match/gen-match.ss @@ -13,6 +13,11 @@ [([pats . rhs] ...) (nest ([parameterize ([orig-stx stx])] + [begin (unless (syntax->list exprs) + (raise-syntax-error + 'match* + "expected a sequence of expressions to match" + exprs))] [let ([len (length (syntax->list exprs))])] [with-syntax ([(xs ...) (generate-temporaries exprs)] [(exprs ...) exprs] @@ -21,9 +26,20 @@ ([body (compile* (syntax->list #'(xs ...)) - (for/list ([pats (syntax->list #'(pats ...))] + (for/list ([clause (syntax->list clauses)] + [pats (syntax->list #'(pats ...))] [rhs (syntax->list #'(rhs ...))]) + (unless (list? pats) + (raise-syntax-error + 'match* + "expected a sequence of patterns" + pats)) (let ([lp (length (syntax->list pats))]) + (when (null? (syntax->list rhs)) + (raise-syntax-error + 'match + "expected at least one expression on the right-hand side" + clause)) (unless (= len lp) (raise-syntax-error 'match