Re: [racket-users] How can I write a macro that recognizes arbitrary other macros?

2020-04-17 Thread Ryan Kramer
Thanks! That was much easier than I was expecting. For posterity, here is some working code but be warned that I don't know whether 'module is the best expansion context to use. But this is a toy example anyway. #lang racket (define-syntax (collect stx) (syntax-case stx (define-values) [

Re: [racket-users] How can I write a macro that recognizes arbitrary other macros?

2020-04-16 Thread Matthew Flatt
The main trick in this case is to recognize `define-values` (which is what `define` expands to) instead of `define`. That's because `define-values` propagates syntax arming to its identifiers and right-hand side, which means that your macro is allowed to pull it apart. You'll also need to use an e

[racket-users] How can I write a macro that recognizes arbitrary other macros?

2020-04-16 Thread Ryan Kramer
The following code produces '(1 2 3 4) (define-syntax (collect stx) (syntax-case stx (define) [(_ (define id val) rest ...) #'(let ([id val]) (collect rest ...))] [(_ (macro arg ...) rest ...) (syntax-local-value #'macro (lambda () #f)) (let ([expanded (local-expa