[racket] stumped by a little macro exercise

From: Richard Mittel (rich.mittel at gmail.com)
Date: Sat Oct 9 14:43:01 EDT 2010


In trying to take up the fall-through case challenge in "a little macro
exercise," I came up with this so far:

(define-syntax cas-cad-e
  (syntax-rules (break go!)
    ((_ go! v () a) (let ((mtc #f)) (call/cc (lambda (break) . a))))
    ((cas-cad-e go! v (((bv ...) . b) . r) (a ...))
     (cas-cad-e go!
        (a ... (when (or mtc
                 (and (memq v '(bv ...))
                      (begin (set! mtc #t) #t)
                 . b))))
    ((_ v br . d) (cas-cad-e go! v (br . d) ()))))

I haven't looked at anyone else's solution yet.  But setting aside questions
of concision and correctness, I can't even run it.  Consider:

> (cas-cad-e 2 ((1) 3))
reference to undefined identifier: mtc

I don't get it.  Isn't mtc safely bound in my let?  Here's the expansion:

> (syntax->datum (expand '(cas-cad-e 2 ((1) 3))))
(let-values (((mtc) '#f))
   (lambda (break)
     (if (let-values (((or-part) (#%top . mtc)))
           (if or-part
             (if (#%app memq '2 '(1)) (begin (set! mtc '#t) '#t) '#f)))
       (begin '3)
       (#%app void)))))

Thanks in advance for your help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101009/691b2cbc/attachment.html>

Posted on the users mailing list.