[plt-scheme] Creating new syntax for decision tables

From: Robby Findler (robby.findler at gmail.com)
Date: Thu Feb 8 18:16:39 EST 2007

Oops, left in a silly bug. Here you go:

(module m mzscheme

  (define-syntax (table stx)
    (syntax-case stx (:)
      [(_ clauses ...)
       (let* ([transpose (λ (l) (apply map list l))]
              [rewrite-clauses
               (λ (clause)
                 (syntax-case clause (:)
                   [(var : tfs ...)
                    (map
                     (λ (tf)
                       (syntax-case tf (T F)
                         [T #'var]
                         [F #'(not var)]
                         [* #'#t]))
                     (syntax->list (syntax (tfs ...))))]))])
         (with-syntax ([((item ...) ...)
                        (transpose (map rewrite-clauses
                                        (syntax->list (syntax (clauses
...)))))])
           #'(or (and item ...) ...)))]))

  (λ (a b c)
    (table
     (a : T T F)
     (b : F * F)
     (c : * F T))))

Posted on the users mailing list.