On Wed, Sep 25, 2013 at 11:31 AM, Konrad Hinsen
<konrad.hin...@fastmail.net>wrote:

>
>    (define-syntax (foo stx)
>      (syntax-parse stx
>                    [(_ id:id (~optional super:id) (field:id ...))
>                     (if (attribute super)
>                         #'(struct id super (field ...))
>                         #'(struct id (field ...)))]))



Unsyntax-splicing to the rescue!

#lang racket
(require (for-syntax syntax/parse))

(define-syntax (foo stx)
  (syntax-parse stx
    [(_ id:id (~optional super:id) (field:id ...))
     #`(struct id
         #,@(if (attribute super)
                (list #'super)
                '())
         (field ...))
     ]))

(struct A (a))

(foo B (b))
(foo C A (c))

(A 1)
(B 2)
(C 3 4)


Laurent
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to