Created
April 1, 2015 20:21
-
-
Save edne/df6ea985ade356331985 to your computer and use it in GitHub Desktop.
playing with macros inside macros: a Clojure-like defmacro in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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