<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 25, 2013 at 11:31 AM, Konrad Hinsen <span dir="ltr"><<a href="mailto:konrad.hinsen@fastmail.net" target="_blank">konrad.hinsen@fastmail.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
(define-syntax (foo stx)<br>
(syntax-parse stx<br>
[(_ id:id (~optional super:id) (field:id ...))<br>
(if (attribute super)<br>
#'(struct id super (field ...))<br>
#'(struct id (field ...)))]))</blockquote></div><br><br></div><div class="gmail_extra">Unsyntax-splicing to the rescue!<br></div><br><div class="gmail_extra">#lang racket<br>(require (for-syntax syntax/parse))<br>
<br>(define-syntax (foo stx)<br> (syntax-parse stx<br> [(_ id:id (~optional super:id) (field:id ...))<br> #`(struct id <br> #,@(if (attribute super)<br> (list #'super)<br> '())<br>
(field ...))<br> ]))<br><br>(struct A (a))<br><br>(foo B (b))<br>(foo C A (c))<br><br>(A 1)<br>(B 2)<br>(C 3 4)<br><br><br></div><div class="gmail_extra">Laurent<br></div></div>