< p >Common Lisp核心库有700多个函数。Clojure的库中大约有多少个函数?< /p >
< p >(其中“核心库”被定义为在您的< code > project.clj < /code >中包括< code > [org.clojure/clojure "1.5.1"] < /code >时可以访问的所有内容)< /p >
使用Clojure 1.5.1。
clojure.core
命名空间:
Public Vars:
(count (ns-publics 'clojure.core))
;= 591
Public Vars which hold non-macro functions (the filter function is meant to exclude the 6 Vars which hold maps, see below for how to find them; there are not sets or vectors to exclude at this time):
(->> (ns-publics 'clojure.core)
vals
(filter #(not (.isMacro %)))
(map deref)
(filter (every-pred ifn? (comp not map?)))
count)
;= 477
With #(.isMacro %)
in the filter
above, we find there are 76 public macros.
The 32 public Vars which do not hold function-like values can be discovered with this snippet:
(->> (ns-publics 'clojure.core)
vals
(remove (comp ifn? deref)))
Use (filter (comp map? deref))
instead of the (remove ...)
in the above to find the 6 Vars holding map values.
对于Clojure jar中所有命名空间,与2.相同(跳过已弃用的clojure.parallel
,并额外排除保存向量的两个变量;目前没有要排除的集合;希望没有漏掉其他内容):
(dorun (map require '[clojure.core clojure.data clojure.edn clojure.inspector
clojure.instant clojure.java.browse clojure.java.javadoc
clojure.java.io clojure.java.shell
clojure.main clojure.pprint clojure.reflect clojure.repl
clojure.set clojure.stacktrace clojure.string
clojure.template clojure.test clojure.walk clojure.xml
clojure.zip]))
(->> (mapcat ns-publics
'[clojure.core
clojure.data
clojure.edn
clojure.inspector
clojure.instant
clojure.java.browse
clojure.java.javadoc
clojure.java.io
clojure.java.shell
clojure.main
clojure.pprint
clojure.reflect
clojure.repl
clojure.set
clojure.stacktrace
clojure.string
clojure.template
clojure.test
clojure.walk
clojure.xml
clojure.zip])
vals
(filter #(not (.isMacro %)))
(map deref)
(filter (every-pred ifn? (comp not map?) (comp not vector?)))
count)
;= 676
对于宏,总数为99。