(a)
(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)
(shift-to (n e s w) (w n e s))

(c)
(let ((tmp n))
   (set! n e)
   (set! e s)
   (set! s w)
   (set! w n))

Example 5: New rotate macro.

Back to Article