Two variations:

#lang racket
(require (for-syntax syntax/parse))

(define (do-something x y) (displayln (list x y)))

(define-syntax-rule (macro (x ...) ys)
  (begin (outer x ys) ...))

(define-syntax-rule (outer x (y ...))
  (begin (do-something x y) ...))

(macro (1 2 3) (4 5))
(newline)

(define-syntax (macro2 stx)
  (syntax-parse stx
    [(_macro2 (x ...) ys)
     (with-syntax ([ooo #'(... ...)])
       #'(begin
           (let ()
             (define-syntax-rule (inner (y ooo))
               (begin (do-something x y) ooo))
             (inner ys))
           ...))]))

(macro2 (1 2 3) (4 5))


2017-09-01 15:48 GMT+02:00 Jos Koot <jos.k...@gmail.com>:

> How about:
>
> (define-syntax (macro stx)
>   (syntax-case stx ()
>     [(_ (var1 ...) (var2 ...))
>      #`(begin
>         #,@(for*/list ((v1 (in-list (syntax->list #'(var1 ...))))
>                        (v2 (in-list (syntax->list #'(var2 ...)))))
>          #`(do-something #,v1 #,v2)))]))
>
> Jos
>
> -----Original Message-----
> From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com]
> On Behalf Of Sam Waxman
> Sent: viernes, 01 de septiembre de 2017 11:37
> To: Racket Users
> Subject: [racket-users] Mapping over pattern variables
>
> Lets say I have a macro
>
> (define-syntax (macro stx)
>   (syntax-parse stx
>     [(_ (var1 ...) (var 2 ...))
>      #'(begin
>          (begin
>            (do-something (#freeze var1) var2)
>            ...)
>          ...)]))
>
> and I want to iterate first over var2, and then over var1. So if I type
>
> (macro (1 2 3) (1 2))
>
> I should get
>
> (begin
>   (begin
>     (do-something 1 1)
>     (do-something 1 2))
>   (begin
>     (do-something 2 1)
>     (do-something 2 2))
>   (begin
>     (do-something 3 1)
>     (do-something 3 2)))
>
> What do I put where I currently have "#freeze" to tell the expander that I
> don't want the ... to affect var1? Or do I have to do
> this manually with syntax->list and mapping functions?
>
>
> --
> 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.
>



-- 
-- 
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.

Reply via email to