[racket-dev] 'case' using equal?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Nov 25 22:11:25 EST 2012

I'm not sure what that error message means, but I think I was thinking
of a different strategy. Something like this (but where you deal with
'else' properly and write in '#%kernel (so you have to use the
expansion of log-info etc etc)), all staying in the same file.

#lang racket
(provide (rename-out [new:case case]))
(define-syntax (new:case stx)
  (with-syntax ([line (syntax-line stx)]
                [fn (syntax-source stx)])
    (syntax-case stx ()
      [(_ exp [(d ...) exp ...])
       #'(let ([x exp])
           (check-em 'fn line x '(d ... ...))
           (case exp [(d ...) exp ...] ...))])))

(define (check-em file line val datums)
  (for ([datum (in-list datums)])
    (unless (eq? (equal? datum val)
                 (eqv? datum val))
       (format "found a difference in ~a:~a; ~s vs ~s"
               file line datum val)))))


On Sun, Nov 25, 2012 at 8:57 PM, Jon Zeppieri <zeppieri at gmail.com> wrote:
> On Sun, Nov 25, 2012 at 7:49 PM, Jon Zeppieri <zeppieri at gmail.com> wrote:
>> Looking back at the users thread, I see what you mean. I'll create a
>> branch that will do what you suggest: evaluate the expression both
>> ways, compare, and complain if the results differ.
> This is not turning out to be as simple as expected.
> I created modules equal-case.rkt and eqv-case.rkt, and then a simple
> case macro in case.rkt that uses both. However, the build fails at:
> make xsrc/precomp.h
> env XFORM_PRECOMP=yes ../racketcgc -cqu ../../../racket/gc2/xform.rkt
> --setup . --cpp "gcc -E -I./.. -I../../../racket/gc2/../include -DOS_X
> -D_DARWIN_UNLIMITED_SELECT -pthread  -fno-common   "  --keep-lines -o
> xsrc/precomp.h ../../../racket/gc2/precomp.c
> /Users/jaz/src/racket/collects/s-exp/lang/reader.rkt:1:36:
> syntax/module-reader: got two #:language keywords
>   in: #:language
>   context...:
>    /Users/jaz/src/racket/collects/syntax/module-reader.rkt:19:14: loop
>    /Users/jaz/src/racket/collects/syntax/module-reader.rkt:35:4:
> construct-reader
>    standard-module-name-resolver
>    standard-module-name-resolver
>    standard-module-name-resolver
>    /Users/jaz/src/racket/src/racket/gc2/xform.rkt:95:24
>    /Users/jaz/src/racket/src/racket/gc2/xform.rkt: [running body]
> make[4]: *** [xsrc/precomp.h] Error 1
> make[3]: *** [all] Error 2
> make[2]: *** [3m] Error 2
> make[1]: *** [3m] Error 2
> make: *** [all] Error 2

Posted on the dev mailing list.