我们怎样才能找出读者宏的作用?
例如,我知道正则表达式#"abc"
与(re-pattern "abc")
相同。
但是以下内容:(macroexpand #"abc" )
会产生#"abc"
,那么我怎样才能从读者特殊形式转到"正常"功能形式?
答案 0 :(得分:3)
您可以使用read-string
(read-string "`(rest ~f)")
=>
(clojure.core/seq
(clojure.core/concat (clojure.core/list (quote clojure.core/rest)) (clojure.core/list f)))
(read-string "#(x %&)")
=> (fn* [& rest__92046#] (x rest__92046#))
(read-string "`(~@x)")
=> (clojure.core/seq (clojure.core/concat x))
(read-string "`(~x)")
=> (clojure.core/seq (clojure.core/concat (clojure.core/list x)))
(read-string "'map")
=> (quote map)
(read-string "#'map")
=> (var map)
(read-string "@x")
=> (clojure.core/deref x)
(binding [*print-meta* true]
(pr-str (read-string "(def ^:foo x 'map)")))
=> "(def ^{:foo true} x (quote map))"
(read-string "#\"x\"")
=> #"x"
在您的特定情况下:正则表达式以同样的方式打印给您,因为that's how it's printed in clojure。
(class #"abc")
=> java.util.regex.Pattern