为什么我定义的函数与clojure / core中的函数的元行为不同?例如:
user=> (defn pr-x [x] (println x))
#'user/pr-x
user=> (meta pr-x)
{:ns #<Namespace user>, :name pr-x}
user=> (meta (var pr-x))
{:ns #<Namespace user>, :name pr-x, :file "NO_SOURCE_PATH", :line 13, :arglists ([x])}
user=> (meta map)
{:ns #<Namespace clojure.core>, :name map, :file "clojure/core.clj", :line 2079, :arglists ([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]), :added "1.0", :doc "Returns a lazy sequence consisting of the result of applying f to the\n set of first items of each coll, followed by applying f to the set\n of second items in each coll, until any one of the colls is\n exhausted. Any remaining items in other colls are ignored. Function\n f should accept number-of-colls arguments."}
user=>
请注意,我必须为用户定义的函数调用(meta (var pr-x))
来获取元数据,而在clojure核心中的函数我可以去(meta map)
并获取元数据。我不明白;为什么差异?
答案 0 :(得分:0)
您使用的是哪个版本?使用1.3,我得到了一致的行为。 (meta map)
为我返回nil,但(meta (var map))
返回{:ns #<Namespace clojure.core>, :name map, :arglists ([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]), :added "1.0", :static true, :doc "Returns a lazy sequence consisting of the result of applying f to the\n set of first items of each coll, followed by applying f to the set\n of second items in each coll, until any one of the colls is\n exhausted. Any remaining items in other colls are ignored. Function\n f should accept number-of-colls arguments.", :line 2414, :file "clojure/core.clj"}