> On Apr 25, 2016, at 3:43 PM, Matthew Butterick <[email protected]> wrote:
> On Apr 24, 2016, at 7:58 PM, Alex Knauth <[email protected]> wrote: >> One way to do this would be to make `(name-parsing-macro x "," y "," z)` a >> match-expander >> Does this work for you? Or is your case more complicated? > > Right, `match` is somewhat special. I'm interested in the more general > problem (another sample posted below) No, not really. `match` is just another macro, and you could reimplement something just like what match expanders do if you wanted to. > ;;;;;;;;;;;;;; > #lang racket > > (define-syntax-rule (binding-form _topid (_id ...)) > (define (_topid) > (let ([_id '_id] ...) > (displayln (format "~a bound ~a" '_topid _id)) ...))) > > (binding-form foo (a b c)) > (foo) ; works > > (define-syntax-rule (id-maker _a "," _b "," _c) > (_a _b _c)) > > (binding-form bar (id-maker a ZIM b ZAM c)) > (bar) ; fails, will treat `(id-maker ..)` expr as list of literal ids > As a rule of thumb, is this accurate: > > You can NEVER use a macro in a binding position (to produce identifiers). > > And therefore the corollary: > > A macro that wants to put identifiers in a binding position MUST produce the > whole binding form for those identifiers. Well, that's pretty much what match expanders are. Although the `match` forms have to recognize these match expanders specially, and expand them itself, one step at a time. You might be interested in Stephen Chang's generic-bind package, which allows macros in binding positions in a way a bit more flexible that what `match` does. documentation: http://docs.racket-lang.org/generic-bind/index.html source code: https://github.com/stchang/generic-bind I was about to try to apply its awesome power to your example, but I just realized that in your new example, the s-expression `(id-maker a ZIM b ZAM c)` isn't actually used in a binding position. Instead the individual ids within it are used in binding positions. Whatever you're thinking of it's probably completely possible with racket's macro system, and it might require similar things to what `match` and `generic-bind` already do, or it might be possible to use one of those, but I'm not sure without knowing more about what you want. -- 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.

