[racket] ok what's wrong there 'syntax-rule' evaluating its operand (??)

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Jan 14 15:12:35 EST 2015

You want something like this: 

(define-syntax (with-tables stx)
  (syntax-case stx () 
    [(with-tables stem body ...)
     (let ([table-author (datum->syntax stx 'table-author)]
           ;; ... ditto for other identifiers for which you wish to break lexical scope 
           )
       #`(let ([table-publication (string-append stem "_publication")]
               [#,table-author (string-append stem "_author")]
               [table-bridge-publication-author (string-append stem "_bridge_publication_author")]
               [table-unique-counters (string-append stem "_unique_counters")])
           body ...))]))

(with-tables "x" table-author)

;; --- 

To achieve this with syntax-rules would be, well, hard.

;; --- 

The accepted way of writing this macro is: 

(define-syntax (with-tables stx)
  (syntax-case stx () 
    [(with-tables stem (table-author
                        ;; ... add other names you wish to bind in body
                        ) 
                  body ...)
     #`(let ([table-publication (string-append stem "_publication")]
             [table-author (string-append stem "_author")]
             [table-bridge-publication-author (string-append stem "_bridge_publication_author")]
             [table-unique-counters (string-append stem "_unique_counters")])
           body ...)]))

(with-tables "x" (table-author) table-author)





Posted on the users mailing list.