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) (void)) ; i.e., do nothing
((rotate a b c ...) (begin
(swap a b)
(rotate b c ...)))))
<b>(b)</b>
(begin
(swap n e)
(rotate e s w))
<b>(c) </b>
(begin
(swap n e)
(begin
(swap e s)
(rotate s w)))
<b>(d)</b>
(begin
(swap n e)
(begin
(swap e s)
(begin
(swap s w)
(void))))
Example 4: rotate macro.