Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save zeptometer/39fbfe489a61348346c1 to your computer and use it in GitHub Desktop.

Select an option

Save zeptometer/39fbfe489a61348346c1 to your computer and use it in GitHub Desktop.
(define (subst old new tree)
(cond ((eq? old tree) new)
((pair? tree)
(cons (subst old new (car tree))
(subst old new (cdr tree))))
(else tree)))
(define-syntax x2y
(ir-macro-transformer
(lambda (form r compare)
(let ((tree (cadr form)))
`',(subst 'x 'y tree)))))
; (x2y (x x y (x ((x z)) z)))
; expect: (y y y (y ((y z)) z)
; => (x x y (x ((x z)) z))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment