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

From: Thomas Lynch (thomas.lynch at reasoningtechnology.com)
Date: Wed Jan 14 20:14:01 EST 2015

Matthias thank you for fielding my question, though two things are not
clear.  I hope you or someone might clarify.

Firstly,  is there a reason to prefer the macro you present over the first
one given in the original post.  I believe they both work.  Neither uses
the more elegant syntax-rule.

Secondly, and this is the question I'm really getting at,  is there a
reason that the operands given to syntax-rules must have identifiers within
lexical scope at the point of the macro call, rather than lexical scope at
the point of their use within the macro?

Off hand the latter seems to be the proper behavior for a macro,  i.e.
perhaps this is a bug?  Can anyone here tell me why it behaves like this?


On Thu, Jan 15, 2015 at 4:12 AM, Matthias Felleisen <matthias at ccs.neu.edu>
wrote:

>
> 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)
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150115/2e8438aa/attachment-0001.html>

Posted on the users mailing list.