[racket] ok what's wrong there 'syntax-rule' evaluating its operand (??)
Here is a macro that is working, .. at least in the context it is being
used:
(define-syntax (with-tables stx)
(let*(
[datum (syntax->datum stx)]
[stem (cadr datum)]
[body (cddr datum)]
)
(datum->syntax stx
(append
`(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
)
racket@> (with-tables "x" (displayln table-publication) table-author)
x_publication
"x_author"
This same functionality as a syntax rule:
(define-syntax with-tables
(syntax-rules ()
[(with-tables stem 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 ...
)
]
))
#|
racket@> (with-tables "x" table-author)
reference to undefined identifier: table-author
stdin::6353: table-author
=== context ===
/usr/share/racket/collects/racket/private/misc.rkt:87:7
|#
Fails with a undefined identifier, but to do that it would have to evaluate
the argument. Ok, so what did I do wrong here?
..not surprisingly, same result with define-syntax-rule ..
(define-syntax-rule (with-tables stem 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 ...
))
#|
racket@> (with-tables "x" table-author)
reference to undefined identifier: table-author
stdin::6353: table-author
=== context ===
/usr/share/racket/collects/racket/private/misc.rkt:87:7
|#
-Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150114/56e4b0eb/attachment.html>