> 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.
> ;; 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))
One way to do this would be to make `(name-parsing-macro x "," y "," z)` a
match-expander:
(require racket/match (for-syntax syntax/parse))
(define-match-expander name-parsing-macro
(syntax-parser
[(name-parsing-macro arg1 "," arg2 "," arg3)
#'(list arg1 arg2 arg3)]))
;; case 2:
(definer-macro (name-parsing-macro x "," y "," z) (val-producing-macro))
(check-equal? x 1)
(check-equal? y 2)
(check-equal? z 3)
Does this work for you? Or is your case more complicated?
Alex Knauth
--
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.