That is a lot more brief than mine. I just adapted a naive, unquoted version from the Racket case:
(define-syntax my-case (syntax-rules (else) [(_ val ((mtch ...) expr) rest ... (else expr2)) (if (my-comp val (mtch ...)) expr (my-case val rest ... (else expr2)))] [(_ val ((mtch ...) expr) (else expr2)) (if (my-comp val (mtch ...)) expr expr2)] [(_ val (else expr)) expr] [(_ val ((mtch ...) expr) rest ...) (my-case val ((mtch ...) expr) rest ... (else #f))])) (define-syntax my-comp (syntax-rules () [(_ v ()) #f] [(_ v (k)) (equal? v k)] [(_ v (k ks ...)) (if (equal? v k) #t (my-comp v (ks ...)))])) On Tue, Dec 23, 2014 at 8:29 PM, Eli Barzilay <e...@barzilay.org> wrote: > On Mon, Dec 22, 2014 at 12:52 AM, Jon Zeppieri <zeppi...@gmail.com> wrote: > > `case` is like C's `switch` (but unlike similar constructs in other > > C's switch does, however, allow the use of constant *expressions* as > > case labels, so you can have something like `case FOO % 3`, where `FOO > > % 3` can be computed at compile-time. > > (define-syntax (case* stx) > (syntax-case stx () > [(_ what [v e ...] ...) > (with-syntax ([(v* ...) (generate-temporaries #'(v ...))]) > #'(let-syntax ([foo (λ(_) (with-syntax ([(v* ...) (list v ...)]) > #'(case what [(v*) e ...] ...)))]) > foo))])) > > (case* 3 > [1 2] > [(+ 1 2) 4]) > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: > http://barzilay.org/ Maze is Life! >
____________________ Racket Users list: http://lists.racket-lang.org/users