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.