[plt-scheme] Applying DRY in macros

From: Noel Welsh (noelwelsh at gmail.com)
Date: Sat Sep 13 18:02:06 EDT 2008

On Sat, Sep 13, 2008 at 10:35 PM,  <danprager at optusnet.com.au> wrote:
> In this instance, however, it looks to me as if the amount of duplication has remained the same, while the apparent complexity -- #`, #,@, #'  -- has increased.  Compare with the earlier:
> (define-syntax for
>  (syntax-rules (in as)
>    ((for element in list body ...)
>     (map (lambda (element)
>            body ...)
>          list))
>    ((for list as element body ...)
>     (for element in list body ...))))
> which I was hoping could be improved on.

The above is how I'd write it; you can't have an "OR" in a pattern in
syntax-rules or syntax-case.  I imagine this is to remove ambiguity in
the parser.   But, there is a better way: apply DRY to the macro
specification, remove one of the choices, and the problem goes away.



Posted on the users mailing list.