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

From: J Arcane (jarcane at gmail.com)
Date: Wed Dec 24 03:19:40 EST 2014

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 <eli at barzilay.org> wrote:

> 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!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141224/93d03f58/attachment.html>

Posted on the users mailing list.