I found a recent tutorial 

  http://willdonnelly.wordpress.com/2008/09/04/a-scheme-syntax-rules-primer/

helpful in starting to come to grips with syntax-rules.
 
It concluded with this example

(define-syntax for
  (syntax-rules (in as)
    ((for element in list body ...)
     (map (lambda (element)
            body ...)
          list))
    ((for list as element body ...)
     (map (lambda (element)
            body ...)
          list))

This left me wondering how to eliminate the repetition -- as per Don't Repeat Yourself (DRY) -- within the macro itself, in this case the repeated template:

     (map (lambda (element)
            body ...)
          list)

In the reddit comments about the tutorial

  http://www.reddit.com/r/programming/comments/710el/a_scheme_syntaxrules_primer/

the following refactoring was suggested

(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 does eliminate the template duplication, but repeats the line 

  (for element in list body ...)

first as a pattern, then as a template.

Can anyone suggest further improvements?

* * *

What I would _like_ to be able to write is something like:

(define-syntax for
  (syntax-rules-with-**magic** (in as)
    (**magic** ([template
                 (map (lambda (element)
                        body ...)
                      list)]))
    ((for element in list body ...) template)
    ((for element in list body ...) template)))

Are constructions like this already possible without further extending the existing macro facilities?  If so, how is it done?  Or could syntax-rules-with-**magic** (or similar) be easily written?




