[racket] syntax-parse question
On Aug 5, 2014, at 2:21 PM, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> 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
Closer. It doesn’t match something like ‘( 1 2 3 (4 5 6) 7 (8 9) 10), for instance.
I have tried:
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (x stx)
(define-syntax-class binding
#:description "binding list"
(pattern (z:id ...)))
(define-syntax-class or-binding
#:description "binding or"
(pattern (~or zb:binding y:id)
#:with (z ...) #'(zb.z ...)))
(syntax-parse stx
[(_ (ob:or-binding ...) ...)
#''ok
#;#'(xf (yf ob.y ...) ...)
#;#'(xf (yf ob.y ... (zf ob.z ...) ...) ...)]))
(define (xf . xs) xs)
(define (yf . ys) ys)
(define (zf . zs) zs)
(x (a))
(x (a b (c)))
(x (a b c (d e f) g h))
But while the pattern “appears” to match, I can’t seem to construct a template that is acceptable to syntax-parse, which doesn’t like the #:with clause on my syntax-class or-binding. I must be missing something.
-Kevin