Last active
December 19, 2015 05:19
-
-
Save unionx/5903819 to your computer and use it in GitHub Desktop.
丧心病狂的使用宏的方法
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
(require '(clojure [string :as string] | |
[walk :as walk])) | |
;; page 236 on <Clojure Programming> | |
(defmacro reverse-it [form] | |
(walk/postwalk #(if (symbol? %) | |
(symbol (string/reverse (name %))) | |
%) | |
form)) | |
(reverse-it | |
(qesod [gra (egnar 5)] | |
(nltnirp (cni gra)))) | |
; 1 | |
; 2 | |
; 3 | |
; 4 | |
; 5 | |
;= nil | |
(macroexpand-1 '(reverse-it | |
(qesod [gra (egnar 5)] | |
(nltnirp (cni gra))))) | |
(comment | |
;; 宏展开之后的实际形式 | |
(doseq [arg (range 5)] | |
(println (inc arg))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment