2024 Clojure 状态调查!中分享您的想法。

欢迎!请参阅关于页面了解有关如何使用本站的一些更多信息。

0
规范

(s/def ::thing (s/cat :a (s/? string?) :b (s/+ number?)))
(s/def ::seq-of (s/+ ::thing))

(s/conform ::seq-of (list "foo" 1 "bar" 2 3 "qux" 4))
;=> [{:a "foo", :b [1]} [{:a "bar", :b [2 3]} {:a "qux", :b [4]}]]

;EXPECTED
;=> [{:a "foo", :b [1]} {:a "bar", :b [2 3]} {:a "qux", :b [4]}]

;; 只有第二个元素重要?
(s/conform ::seq-of (list "foo" 1 2 "bar" 3))
;=> [{:a "foo", :b [1 2]} {:a "bar", :b [2]}]

;; 不包含可选值
(s/def ::thing (s/cat :a string? :b (s/+ number?)))
(s/def ::seq-of (s/+ ::thing))
(s/conform ::seq-of (list "foo" 1 "bar" 2 3 "qux" 4))
;=> [{:a "foo", :b [1]} {:a "bar", :b [2 3]} {:a "qux", :b [4]}]


也只有在第二个或之后的::thing中包含 2+ 个数字时会显示
如果将 :a 设置为非可选的话,问题就会消失...

可能与 http://dev.clojure.org/jira/browse/CLJ-2003 相关?

1 答案

0
参考:https://clojure.atlassian.net/browse/CLJ-2105 (由 alex+import 报告)
...