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 中存在两个或更多数字时出现。
如果我把 :a 设置为非可选的,问题就会消失...

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

1 个答案

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