Re: [racket-users] Lost in ellipsis depths
Here's one more solution, using "template metafunctions" (inspired by Redex's metafunctions). And yes, most of the point of template metafunctions is to have something that cooperates with ellipses like you want. > (require syntax/parse syntax/parse/experimental/template racket/syntax) > (define-template-metafunction join (syntax-parser [(_ a:id b:id) (format-id #'a "~a-~a" #'a #'b)])) > (syntax-parse #'(foo a b c) [(f:id s:id ...) (template (list (join f s) ...))]) # Ryan On 9/2/15 7:00 AM, Konrad Hinsen wrote: Hi everyone, I am working on what I consider a simple macro, but after reading all of the macro-related documentation twice, I still don't see how to do this. I want to transform (foo a b c) to (list foo-a foo-b foo-c) Here is my best attempt (using syntax/parse): (syntax-parse #'(foo a b c) [(f:id s:id ...) (list (format-id #'f "foo-~a" #'s) ...)]) This yields the error message syntax: missing ellipsis with pattern variable in template In fact, what I want is do something like map over the ellipsis pattern, but I haven't seen any example for doing this. Help, please! Thanks in advance, Konrad. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Lost in ellipsis depths
Jens Axel Søgaard writes: > Here are two variations: ... Alexander D. Knauth writes: > To make it look a little less messy, here's what I would do for stuff like > this: ... Matthias Felleisen writes: > I think you want either this: ... Ryan Culpepper writes: > Here's one more solution, using "template metafunctions" (inspired by > Redex's metafunctions). And yes, most of the point of template > metafunctions is to have something that cooperates with ellipses like > you want. Thanks to all of you for your suggestions! For my current ten-line macro, I'll go with stx-map, but I really like Ryan's template metafunctions for more complex situations, which I expect to run into quite soon. Konrad. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Lost in ellipsis depths
I think you want either this: (syntax-parse #'(foo a b c) [(f:id s:id ...) (map (λ (s) (format-id #'f "foo-~a" s)) (syntax->list #'(s ...)))]) or that: (syntax-parse #'(foo a b c) [(f:id s:id ...) #'(list (format-id #'f "foo-~a" #'s) ...)]) On Sep 2, 2015, at 7:00 AM, Konrad Hinsenwrote: > Hi everyone, > > I am working on what I consider a simple macro, but after reading all > of the macro-related documentation twice, I still don't see how to do > this. > > I want to transform > > (foo a b c) > > to > > (list foo-a foo-b foo-c) > > Here is my best attempt (using syntax/parse): > > (syntax-parse #'(foo a b c) > [(f:id s:id ...) > (list (format-id #'f "foo-~a" #'s) ...)]) > > This yields the error message > > syntax: missing ellipsis with pattern variable in template > > In fact, what I want is do something like map over the ellipsis pattern, > but I haven't seen any example for doing this. > > Help, please! > > Thanks in advance, > Konrad. > > -- > 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 racket-users+unsubscr...@googlegroups.com. > 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Lost in ellipsis depths
Here are two variations: #lang racket (require syntax/stx syntax/parse racket/syntax unstable/sequence) (syntax-parse #'(foo a b c) [(f:id s:id ...) (define foo-s* (stx-map (λ (x) (format-id #'f "foo-~a" x)) #'(s ...))) (with-syntax ([(foo-s ...) foo-s*]) #'(list foo-s ...))]) (syntax-parse #'(foo a b c) [(f:id s:id ...) (define foo-s* (for/list ([x (in-syntax #'(s ...))]) (format-id #'f "foo-~a" x))) (with-syntax ([(foo-s ...) foo-s*]) #'(list foo-s ...))]) 2015-09-02 13:09 GMT+02:00 Konrad Hinsen: > Konrad Hinsen writes: > > > In fact, what I want is do something like map over the ellipsis pattern, > > but I haven't seen any example for doing this. > > Well, map actually works: > > (syntax-parse #'(foo a b c) > [(f:id s:id ...) > (with-syntax ([(foo-s ...) > (map (λ (x) (format-id #'f "foo-~a" x)) (syntax-e #'(s > ...) ))]) >#'(list foo-s ...))]) > > But is this the only solution? It looks a bit messy. > > Konrad. > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- Jens Axel Søgaard -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Lost in ellipsis depths
> On Sep 2, 2015, at 7:09 AM, Konrad Hinsenwrote: > > Konrad Hinsen writes: > >> In fact, what I want is do something like map over the ellipsis pattern, >> but I haven't seen any example for doing this. > > Well, map actually works: > > (syntax-parse #'(foo a b c) >[(f:id s:id ...) > (with-syntax ([(foo-s ...) >(map (λ (x) (format-id #'f "foo-~a" x)) (syntax-e #'(s > ...) ))]) > #'(list foo-s ...))]) > > But is this the only solution? It looks a bit messy. > > Konrad. To make it look a little less messy, here's what I would do for stuff like this: (require fancy-app syntax/parse syntax/stx) ; in a for-syntax if necessary (syntax-parse #'(foo a b c) [(f:id s:id ...) #:with (foo-s ...) (stx-map (format-id #'f "foo-~a" _) #'(s ...)) ; the _ makes a fancy-app anonymous function #'(list foo-s ...)]) Or if it's something more complicated, I would use a for/list instead of a stx-map. 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.