<div dir="ltr">Hi friends,<div><br></div><div style>I'm working on a macro that expands into a match statement. It looks something like</div><div style><br></div><div style>(define-syntax (my-macro stx)</div><div style>
(syntax-case stx ()</div><div style> [(_ (id1 id2 ...) body ...)</div><div style> (with-syntax ([match-pattern </div><div style> (datum->syntax stx (cons 'list (syntax->datum #'(id1 id2 ...))))])</div>
<div style> #'(lambda (expr)</div><div style> (match expr</div><div style> [match-pattern body ...])))))</div><div style><br></div><div style>So in effect, it expands</div><div style><br></div><div style>
(my-macro (push i) (printf "~v" i)</div><div style><br></div><div style>into</div><div style><br></div><div style>(lambda (expr)</div><div style> (match expr</div><div style> [(list push i) (printf "~v" i)]))</div>
<div style><br></div><div style>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</div>
<div style><br></div><div style>((my-macro (push i) i) '(dont-push 45)) will evaluate to 45, rather than fail to match (the desired behavior).</div><div style><br></div><div style>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.</div>
<div style><br></div><div style>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?</div><div style><br>Any help would be appreciated. Thanks for your time; I'm loving my explorations into Racket ^_^</div>
<div style><br></div><div style>-Paul</div></div>