Skip to content

Instantly share code, notes, and snippets.

@unionx

unionx/reverse-it.clj

Last active Dec 19, 2015
Embed
What would you like to do?
丧心病狂的使用宏的方法
(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