[racket] syntax-parse question

From: Kevin Forchione (lysseus at gmail.com)
Date: Tue Aug 5 16:44:59 EDT 2014

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

Posted on the users mailing list.