[racket] Question on (quote var) in macros

From: Paul Meier (pablo.a.meier at gmail.com)
Date: Wed Jan 16 00:22:27 EST 2013

Hi friends,

I'm working on a macro that expands into a match statement. It looks
something like

(define-syntax (my-macro stx)
  (syntax-case stx ()
    [(_ (id1 id2 ...) body ...)
     (with-syntax ([match-pattern
                          (datum->syntax stx (cons 'list (syntax->datum
#'(id1 id2 ...))))])
     #'(lambda (expr)
         (match expr
            [match-pattern body ...])))))

So in effect, it expands

(my-macro (push i) (printf "~v" i)

into

(lambda (expr)
  (match expr
    [(list push i) (printf "~v" i)]))

Here is the problem: I'd like the first entry of the match list to be
quoted (e.g. 'push) rather than unquoted, as it is above, since 'match'
will interpret this as a free variable, meaning

((my-macro (push i) i) '(dont-push 45)) will evaluate to 45, rather than
fail to match (the desired behavior).

Unfortunately, trusty (quote (syntax->datum stx id1)) and or any variation
thereof will do what it's supposed to: quote whatever expression will
evaluate into whatever I want quoted.

I could just write the quotes into the expressions using the macro, a la
(my-macro ('push i) ...), but Shirly there's a way around this?

Any help would be appreciated. Thanks for your time; I'm loving my
explorations into Racket ^_^

-Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130115/14756082/attachment-0001.html>

Posted on the users mailing list.