[racket] Why does (case ...) quote its matching value expressions?

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Dec 23 13:29:42 EST 2014

On Mon, Dec 22, 2014 at 12:52 AM, Jon Zeppieri <zeppieri at 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!


Posted on the users mailing list.