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 swap(...) ...
<b>(b)</b>
(define-syntax swap (syntax-rules ... ...))
<b>(c)</b>
(define-syntax swap
(syntax-rules ()
((swap a b) (let ((tmp b))
(set! b a)
(set! a tmp)))))
Example 2: Scheme macro basics.