You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-lib/br/define.rkt

19 lines
677 B
Racket

9 years ago
#lang racket/base
(require (for-syntax racket/base syntax/parse) br/macro)
(provide (all-defined-out) (all-from-out br/macro))
8 years ago
(define-syntax (define-cases stx)
9 years ago
(syntax-parse stx
#:literals (syntax)
8 years ago
[(_ id:id)
(raise-syntax-error 'define-cases "no cases given" (syntax->datum #'id))]
[(_ id:id [(_ . pat-args:expr) . body:expr] ...)
#'(define id
9 years ago
(case-lambda
9 years ago
[pat-args . body] ...
8 years ago
[rest-pat (apply raise-arity-error 'id (normalize-arity (map length '(pat-args ...))) rest-pat)]))]
8 years ago
[else (raise-syntax-error
'define-cases
"no matching case for calling pattern"
(syntax->datum stx))]))