>From the hip: Can your name-producing macro consume (val-producing-macro) and >then just directly generate the case-2 macro call directly:
#lang racket (require rackunit) (define-syntax-rule (definer-macro ids vals) (match-define ids vals)) (define-syntax-rule (val-producing-macro) (list 1 2 3)) ;; case 1 (definer-macro (list a b c) (val-producing-macro)) ; binds a b c (check-equal? a 1) (check-equal? b 2) (check-equal? c 3) (define-syntax-rule (name-parsing-macro arg1 "," arg2 "," arg3 e) (definer-macro (list arg1 arg2 arg3) e)) (name-parsing-macro arg1 "," arg2 "," arg3 (val-producing-macro)) (check-equal? arg1 1) (check-equal? arg2 2) (check-equal? arg3 3) > On Apr 24, 2016, at 7:21 PM, Matthew Butterick <[email protected]> wrote: > > This probably has an obvious answer in the syntax library but the problem is > new to me. > > The `definer-macro` below wants to bind identifiers that have been introduced > at the caller site. Case 1 works as expected. > > But consider case 2, where another macro picks up identifiers from the > calling site, rearranges them, and then tries to put them back. This doesn't > work because, IIUC, it would need to reverse the usual evaluation order. > > Is there a way to rewrite `definer-macro` to prevent this error? I imagine it > looks like this but as usual it's the `magic-goes-here` part that's > troublesome. > > (define-syntax (definer-macro stx) > (syntax-case stx () > [(_ ids vals) > (with-syntax ([(id ...) (magic-goes-here #'ids)] > [(val ...) (magic-goes-here #'vals)]) > #'(match-define (id ...) (val ...)))])) > > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > #lang racket > (require rackunit) > > (define-syntax-rule (definer-macro ids vals) > (match-define ids vals)) > > (define-syntax-rule (val-producing-macro) (list 1 2 3)) > > ;; case 1 > (definer-macro (list a b c) (val-producing-macro)) ; binds a b c > > (check-equal? a 1) > (check-equal? b 2) > (check-equal? c 3) > > (define-syntax-rule (name-parsing-macro arg1 "," arg2 "," arg3) > (list arg1 arg2 arg3)) > > ;; case 2: how to avoid the error? > ;; (definer-macro (name-parsing-macro x "," y "," z) (val-producing-macro)) > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

