Building Little Languages with Macros
By Matthias Felleisen, Robert Bruce Findler, Matthew Flatt and and Shriram Krishnamurthi, April 01, 2004
Source Code Accompanies This Article. Download It Now.
Pattern-based macros in Scheme can express interesting language extensions.
Apr04: Building Little Languages With Macros
<b>(a)</b>
(define-syntax rotate
(syntax-rules ()
((rotate a c ...)
(shift-to (c ... a) (a c ...)))))
(define-syntax shift-to
(syntax-rules ()
((shift-to (from0 from ...) (to0 to ...))
(let ((tmp from0))
(set! to from) ...
(set! to0 tmp)) )))
<b>(b)</b>
(shift-to (n e s w) (w n e s))
<b>(c)</b>
(let ((tmp n))
(set! n e)
(set! e s)
(set! s w)
(set! w n))
Example 5: New rotate macro.