【发布时间】:2019-10-12 12:32:41
【问题描述】:
我对 clojure 的 doc 有点困惑。
输出是参数的规范,使用传统的basic regular expression markup,即:
-
*: 0..n 标记的前面元素的实例(“many”) -
?: 0..1 标记的前面元素的实例(“可选”) -
+: 1..n 个标记的前面元素的实例(“至少一个”)
括号() 和方括号[] 但是,“按给定”用于形成正确的表达式 或形式,并且不使用用于对任何正则表达式元素进行分组。
如果有几个有效的参数组合,它们会被列在几行上。
但例如观察(doc fn) 的输出:
clojure.core/fn
(fn name? [params*] exprs*)
(fn name? ([params*] exprs*) +)
([& sigs])
Special Form
params => positional-params* , or positional-params* & next-param
positional-param => binding-form
next-param => binding-form
name => symbol
Defines a function
Please see http://clojure.org/special_forms#fn
params => positional-params* , or positional-params* & next-param
positional-param => binding-form
next-param => binding-form
name => symbol
Defines a function
Spec
args: (cat :fn-name (? simple-symbol?) :fn-tail (alt :arity-1 :clojure.core.specs.alpha/params+body :arity-n (+ (spec :clojure.core.specs.alpha/params+body))))
ret: any?
nil
前三行的含义如下:
- var 或 特殊形式 的包和名称
- 一个有效的表达式结构
(fn name? [params*] exprs*) - 另一种可能的表达式结构
(fn name? ([params*] exprs*) +)
但是有一个非缩进的([& sigs])。这是关于什么的?
随后的输出似乎也需要清理。什么是“规格”?
对于(doc doc):
clojure.repl/doc
([name])
Macro
Prints documentation for a var or special form given its name,
or for a spec if given a keyword
nil
我不明白没有缩进的([name])。
或者我们试试(doc letfn):
clojure.core/letfn
(letfn [fnspecs*] exprs*)
([fnspecs & body])
Special Form
fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)
Takes a vector of function specs and a body, and generates a set of
bindings of functions to their names. All of the names are available
in all of the definitions of the functions, as well as the body.
fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)
Takes a vector of function specs and a body, and generates a set of
bindings of functions to their names. All of the names are available
in all of the definitions of the functions, as well as the body.
nil
我还不清楚([fnspecs & body]) 的含义。
【问题讨论】:
标签: clojure