From da3ee270457857a3c1f83bcdea5ca4fa32de209f Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 11 Aug 2016 19:13:43 -0700 Subject: [PATCH] update define --- beautiful-racket-lib/br/define.rkt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/beautiful-racket-lib/br/define.rkt b/beautiful-racket-lib/br/define.rkt index bfad0e7..23503d0 100644 --- a/beautiful-racket-lib/br/define.rkt +++ b/beautiful-racket-lib/br/define.rkt @@ -1,5 +1,6 @@ #lang racket/base (require + racket/function (for-syntax racket/list racket/base syntax/parse @@ -56,7 +57,7 @@ #'(define id (case-lambda [pat-args . body] ... - [else (raise-syntax-error 'id "no matching case for argument pattern")]))] + [rest-pat (apply raise-arity-error 'id (normalize-arity (map length '(pat-args ...))) rest-pat)]))] [else (raise-syntax-error 'define-cases "no matching case for calling pattern" @@ -66,9 +67,15 @@ (module+ test (define-cases f [(_ arg) (add1 arg)] - [(_ arg1 arg2) (+ arg1 arg2)]) + [(_ arg1 arg2) (+ arg1 arg2)] + [(_ . any) 'boing]) (check-equal? (f 42) 43) - (check-equal? (f 42 5) 47)) + (check-equal? (f 42 5) 47) + (check-equal? (f 42 5 'zonk) 'boing) + + (define-cases f-one-arg + [(_ arg) (add1 arg)]) + (check-exn exn:fail:contract:arity? (λ _ (f-one-arg 1 2 3)))) (define-syntax-rule (debug-define-macro (ID . PAT-ARGS) BODY)