[racket] define-match-expander
2013/12/29 Alexander D. Knauth <alexander at knauth.org>:
> I'm not really sure why this works either, but try this:
>
> (define-syntax (:match stx)
> (syntax-case stx ()
> [(:match val-expr [pat . more] ...)
> (with-syntax ([(new-pat ...) (for/list ([pat-stx (in-list (syntax->list
> #'(pat ...)))])
> (datum->syntax pat-stx `(:pat
> ,(syntax->datum pat-stx))))])
> #'(match val-expr [new-pat . more] ...))]))
>
> (check-equal? (:match '(42 x) [(list n:num s:sym) (list n s)])
> (match '(42 x) [(:pat (list n:num s:sym)) (list n s)]))
Nice!
/Jens Axel