<div class="h5"><br>
</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I meant in the argument to `datum-&gt;syntax&#39;...<br></blockquote></div><br>Ah, great, this is even better.<br>

I can&#39;t believe its so small in the end...<br><br>For the sake of it, here is what we have now:<br><br>#lang racket<br><br>(provide define-syntax-rule/id)<br><br>;;; By Jon Rafkind (+ tweakings)<br><br>;; Like define-syntax-rule, but takes an additional ([id id-rename] ...) set<br>

;; where the id can be used in body, <br>;; and each id in body is replaced by the result of the id-rename expression.<br>(define-syntax (define-syntax-rule/id stx)<br>  (syntax-case stx ()<br>    [(_ (name arg ...)<br>        ([id id-rename] ...)<br>

        body ...)<br>     #&#39;(define-syntax (name stx2)<br>         (syntax-case stx2 ()<br>           [(_ arg ...) ; This comes from above!<br>            ; We want the defined ids to have the same lexical scope as<br>

            ; the defined macro itself.<br>            (with-syntax ([id (datum-&gt;syntax<br>                               stx2<br>                               (string-&gt;symbol<br>                                ; id-rename is an expression that comes from above.<br>

                                ; it will be replaced by its code in the first expansion<br>                                ; (the first syntax-case),<br>                                ; and this code will be executed in the second expansion.<br>

                                (let ([arg (syntax-e #&#39;arg)] ...)<br>                                  id-rename)) <br>                               stx2 stx2 stx2<br>                               )]<br>                          ...)<br>

              ; id is correctly bound in body here because<br>              ; body is replaced by the full expression (containing id)<br>              ; in this submacro (just like for id-rename).<br>              #&#39;(begin body ...))]))<br>

       ]))<br><br>#| TESTS: |#<br><br>; use the macro stepper to see how it is expanded<br>(define-syntax-rule/id (make-getter-setter xid1 xid2)<br>  ([getter (format &quot;get-~a-~a&quot; xid1 xid2)]<br>   [setter (format &quot;set-~a-~a&quot; xid1 xid2)]<br>

   [xchger (format &quot;xch-~a-~a&quot; xid1 xid2)])<br>  (define (getter) (values xid1 xid2))<br>  (define (setter v1 v2) (set! xid1 v1) (set! xid2 v2))<br>  (define (xchger) (setter xid2 xid1))<br>  )<br><br>(define x1 5)<br>

(define x2 6)<br>(make-getter-setter x1 x2)<br>(get-x1-x2)<br>(set-x1-x2 10 11)<br>(get-x1-x2)<br>(xch-x1-x2)<br>(get-x1-x2)<br><br>;|#<br>