See also `in-syntax`:
http://docs.racket-lang.org/reference/sequences.html?q=in-syntax#%28def._%28%28lib._racket%2Fsequence..rkt%29._in-syntax%29%29

-Philip

On Fri, Sep 1, 2017 at 9:25 AM, Jens Axel Søgaard <jensa...@soegaard.net>
wrote:

> One more:
>
> (begin-for-syntax
>   (define (in-syntax-list stx) (in-list (syntax->list stx)))
>   (require (for-syntax racket/base ))
>   (define-syntax (for*/syntax-list stx)
>     (syntax-case stx ()
>       [(_for*/syntax-list head (for-clause ...) body-or-break ... body)
>
>        #'(datum->syntax #'stx (cons head (for*/list (for-clause ...)
> body-or-break ... body)))])))
>
> (define-syntax (macro3 stx)
>   (syntax-case stx ()
>     [(_ (x ...) (y ...))
>      (for*/syntax-list #'begin
>        ([x (in-syntax-list #'(x ...))]
>         [y (in-syntax-list #'(y ...))])
>        (with-syntax ([x x] [y y])
>          #'(do-something x y)))]))
>
>
> 2017-09-01 15:57 GMT+02:00 Jens Axel Søgaard <jensa...@soegaard.net>:
>
>> 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@googlegro
>>> ups.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
>>
>>
>
>
> --
> --
> 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.
>

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