<div dir="ltr">Thanks guys.  I was going to use syntax/parse eventually anyway since the final version will require syntax-classes etc, but I wanted to build a simple version first since macros are still my nemesis :)</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 8, 2014 at 12:33 PM, Stephen Chang <span dir="ltr"><<a href="mailto:stchang@ccs.neu.edu" target="_blank">stchang@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yeah I'm pretty sure syntax-case won't let you do that.<br>
<br>
One solution is to use syntax-parse, which is (almost) a drop-in<br>
replacement for syntax-case (omit the list of literals), but with many<br>
additional features.<br>
<br>
#lang racket<br>
<div class="im">(require (for-syntax syntax/parse))<br>
<br>
(define-syntax (define/test stx)<br>
  (syntax-parse stx<br>
</div><div class="im">    [(_ (id arg ...) body ... #:test test-expr ...)<br>
     #'(define (id arg ...) body ... test-expr ...)]))<br>
<br>
</div><div class="im">(define/test (my-fn a b c)<br>
  (print a)<br>
  (print b)<br>
  (print c)<br>
  #:test<br>
</div>  (print 'test1)<br>
  (print 'test2))<br>
(define-values (x y z) (values 10 20 30))<br>
(my-fn x y z)<br>
<br>
=> 102030'test1'test2<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jan 8, 2014 at 2:58 PM, Scott Klarenbach <<a href="mailto:scott@pointyhat.ca">scott@pointyhat.ca</a>> wrote:<br>
> I have a macro that modifies define to perform some additional processing.<br>
><br>
> (define-syntax (define/test stx)<br>
>   (syntax-case stx ()<br>
> [(_ (id arg ...) body ... #:test test-expr)<br>
> #'(define (id arg ...) body ... test-expr)]))<br>
><br>
> (define/test (my-fn a b c)<br>
>   (print a)<br>
>   (print b)<br>
>   (print c)<br>
>   #:test<br>
>   (print 'test))<br>
><br>
> This works, but only if test-expr is one expression or wrapped in a begin or<br>
> something.  I'd like the test-expr to be the same as the define body.  I<br>
> wish I could write:<br>
><br>
> (define-syntax (define/test stx)<br>
>   (syntax-case stx ()<br>
> [(_ (id arg ...) body ... #:test test-expr ...)<br>
>  #'(define (id arg ...) body ... test-expr ...)]))<br>
><br>
> But I get a "misplaced ellipsis in pattern" error.<br>
><br>
> I could change the pattern to something like (body ...) #:test (test-body<br>
> ...), but now the syntax of the macro has changed to include the extra<br>
> parenthesis.<br>
><br>
> Am I making a simple mistake?  Or am I resigned to manually parsing out the<br>
> single test-expr into multiple forms in the template?<br>
><br>
> Thanks.<br>
> --<br>
> Talk to you soon,<br>
><br>
> Scott Klarenbach<br>
><br>
> PointyHat Software Corp.<br>
> <a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>
> p <a href="tel:604-568-4280" value="+16045684280">604-568-4280</a><br>
> e <a href="mailto:scott@pointyhat.ca">scott@pointyhat.ca</a><br>
> 200-1575 W. Georgia<br>
> Vancouver, BC V6G2V3<br>
><br>
> _______________________________________<br>
> To iterate is human; to recur, divine<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> ____________________<br>
>   Racket Users list:<br>
>   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Talk to you soon,<br><br>Scott Klarenbach<br><br>PointyHat Software Corp.<br><a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>
p 604-568-4280<br>e <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a><br><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">200-1575 W. Georgia</span><br>
Vancouver, BC <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">V6G2V3</span><br><br>_______________________________________<br>To iterate is human; to recur, divine
</div>