[racket] a little macro exercise

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Oct 9 00:33:52 EDT 2010

8 minutes ago, Jay McCarthy wrote:
> Alright, here's the version with no mutation:

(cas-cad-e 1 [(1) (values 1 2 3)])

In other words:

(define-syntax-rule (cas-cad-e e [(n ...) code ...] ...)
  (let/ec esc
    (syntax-parameterize ([break (make-rename-transformer #'esc)])
      (let*-values ([(tmp) e]
                    [(earlier? ret) (values #f (void))]
                    [(earlier? ret)
                     (if (or earlier? (equal? tmp n) ...)
                       (values #t (call-with-values (lambda () code ...) list))
                       (values earlier? ret))]
                    ...)
        (apply values ret)))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.