syntax-parse and iterecursion

35 views
Skip to first unread message

Hendrik Boom

unread,
Sep 21, 2019, 4:29:11 PM9/21/19
to Racket Users
I've read the syntax-parse and its documentation, and I'd like to know
if there's a way for a macro to accept a varying number of parameters
without them having to be handled in a uniform way, spliced into a list.

I'd like to be able to expand
(foo a1 a2 a3 a4 a5)
into something like
(bar a1 (bar a2 (bar a3 (bar a4 (bar a5 (barend))))))
or even something fancier, something recursively instead of iteratively defined.
-- hendrik

Philip McGrath

unread,
Sep 21, 2019, 4:45:01 PM9/21/19
to Racket Users
I'm not sure if I understand your question; do you mean something like this?
#lang racket
(require syntax/parse/define)
(define-syntax-parser macro-list
  [(_)
   #'null]
  [(_ x0 x ...)
   #'(cons x0 (macro-list x ...))])
(macro-list 1 2 3 4 5)

-Philip


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20190921202908.s7mgnqoxvs4lphgk%40topoi.pooq.com.

Hendrik Boom

unread,
Sep 21, 2019, 8:01:23 PM9/21/19
to Racket Users
On Sat, Sep 21, 2019 at 04:44:47PM -0400, Philip McGrath wrote:
> I'm not sure if I understand your question; do you mean something like this?
> #lang racket
> (require syntax/parse/define)
> (define-syntax-parser macro-list
> [(_)
> #'null]
> [(_ x0 x ...)
> #'(cons x0 (macro-list x ...))])
> (macro-list 1 2 3 4 5)
>
> -Philip

Yes.. That might do the trick!

-- hendrik

>
>
> On Sat, Sep 21, 2019 at 4:29 PM Hendrik Boom <hen...@topoi.pooq.com> wrote:
>
> > I've read the syntax-parse and its documentation, and I'd like to know
> > if there's a way for a macro to accept a varying number of parameters
> > without them having to be handled in a uniform way, spliced into a list.
> >
> > I'd like to be able to expand
> > (foo a1 a2 a3 a4 a5)
> > into something like
> > (bar a1 (bar a2 (bar a3 (bar a4 (bar a5 (barend))))))
> > or even something fancier, something recursively instead of iteratively
> > defined.
> > -- hendrik
> >
> > --
> > 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...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/racket-users/20190921202908.s7mgnqoxvs4lphgk%40topoi.pooq.com
> > .
> >
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAH3z3gZAGw7yoRyGg7_457UUrCfWdeeTLnYS5iCiahUnK%3DvgAQ%40mail.gmail.com.

Hendrik Boom

unread,
Sep 21, 2019, 8:07:58 PM9/21/19
to Racket Users
On Sat, Sep 21, 2019 at 08:01:16PM -0400, Hendrik Boom wrote:
> On Sat, Sep 21, 2019 at 04:44:47PM -0400, Philip McGrath wrote:
> > I'm not sure if I understand your question; do you mean something like this?
> > #lang racket
> > (require syntax/parse/define)
> > (define-syntax-parser macro-list
> > [(_)
> > #'null]
> > [(_ x0 x ...)
> > #'(cons x0 (macro-list x ...))])
> > (macro-list 1 2 3 4 5)
> >
> > -Philip
>
> Yes.. That might do the trick!

In fact, I must have tried something like that, had it fail for irrelevant
but misunderstood reasons, and figured it wouldn't work...
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20190922000116.vvseni6f5aj3hl3o%40topoi.pooq.com.
Reply all
Reply to author
Forward
0 new messages