Skip to content

Instantly share code, notes, and snippets.

@unionx
Last active December 19, 2015 05:19
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 unionx/5903819 to your computer and use it in GitHub Desktop.
Save unionx/5903819 to your computer and use it in GitHub Desktop.
丧心病狂的使用宏的方法
(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