[plt-scheme] Applying DRY in macros
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.
:)
N.
N.