spec/and
在 Clojure 1.9.0-alpha13 中,我可以使用andinteger?
但不是and
and来定义规范谓词number?
,它会出现。这令人费解。令人费解的是,当我定义谓词时没有错误,但只有当我尝试使用它定义规范时。
user=> (use '[clojure.spec :as s])
...
nil
user=> (s/def pos-int? (s/and integer? pos?))
user/pos-int?
user=> (s/def ::foo pos-int?)
:user/foo
user=> (s/def pos-num? (s/and number? pos?))
user/pos-num?
user=> (s/def ::bar pos-num?)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: pos-num? ...
为什么我在第二种情况下得到错误,而不是第一种?这是一个涉及我不知道的区别的功能,还是一个错误?
请注意,如果我直接定义没有错误::bar
:
user=> (s/def ::bar (s/and number? pos?))
:user/bar