[racket] syntax-parse question

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Aug 5 17:21:20 EDT 2014

Is this a step in the right direction?

(define-syntax (x stx)
 (syntax-parse stx
   [(_ (y ... (z ...) w ...))
    #'(xf (yf y ... (zf z ...) w ...))]))

The pattern (z ...) ... will match a sequence of lists such as (4 5 6) (7 8)
but it won't match (4 5 6) 7 8 from your example.

/Jens Axel


2014-08-05 22:44 GMT+02:00 Kevin Forchione <lysseus at gmail.com>:
> I’m interested in using syntax-parse to restructure the form (x (y … (z …) …)) but my coding of syntax-parse appears to be matching the (z …)  as a y. I must be doing something wrong!
>
> Here’s the code:
>
> #lang racket
>
> (require (for-syntax syntax/parse))
>
> (define-syntax (x stx)
>  (syntax-parse stx
>    [(_ (y ... (z ...) ...))
>     #'(xf (yf y ... (zf z ...) ...))]))
>
> (define (xf . xs) (list xs))
> (define (yf . ys) (list ys))
> (define (zf . zs) (list zs))
>
> (x (1 2 3 (4 5 6) 7 8))
>
> Which is expanding to:
>
> Expansion finished
> (module anonymous-module racket
>  (#%module-begin
>   (require (for-syntax syntax/parse))
>   (define-syntax (x stx)
>     (syntax-parse
>      stx
>      [(_ (y ... (z ...) ...))
>       #'(xf (yf y ... (zf z ...) ...))]))
>   (define (xf . xs) (list xs))
>   (define (yf . ys) (list ys))
>   (define (zf . zs) (list zs))
>   (xf (yf 1 2 3 (4 5 6) 7 8))))
>
> I’m expecting (xf (yf 123 (zf 4 5 6) 7 8))))
>
> —Kevin
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


Posted on the users mailing list.