Skip to content

Instantly share code, notes, and snippets.

@edne
Created April 1, 2015 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edne/df6ea985ade356331985 to your computer and use it in GitHub Desktop.
Save edne/df6ea985ade356331985 to your computer and use it in GitHub Desktop.
playing with macros inside macros: a Clojure-like defmacro in Racket
(define-syntax defmacro
(syntax-rules
()
((defmacro (name . args)
(body ...))
(define-syntax name
(syntax-rules
()
((name . args) (body ...)))))))
; test
(defmacro (swap! x y)
(let ((tmp x))
(begin (set! x y)
(set! y tmp))))
(let ((x " before ")
(y " after "))
(begin (swap! x y)
(display x)
(display y)
(newline)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment