以下示例显示了一种情况,其中已符合的表单在进行unform后没有符合任何内容。我期望您可以持续重复conform -> unform -> conform而得到相同的结果。
(require '[clojure.core.specs)])
(require '[clojure.spec :as s)])
(s/def ::defn-macro (s/cat :type #{'defn} :definition :clojure.core.specs/defn-args))
(let [form '(defn foo "bar" ([a & b] a a c) ([a b] a))]
(-> form
(->> (s/conform ::defn-macro))) ;;=> {:type defn, :definition {:name foo, :docstring "bar", :bs [:arity-n {:bodies [{:args {:args [[:sym a]], :varargs {:amp &, :form [:sym b]}}, :body [a a c]} {:args {:args [[:sym a] [:sym b]]}, :body [a]}]}]}}
;; Unforming returns the function definition, but with the args in a list instead of a vector
(->> form
(s/conform ::defn-macro)
(s/unform ::defn-macro)) ;;=> (defn foo "bar" ((a (& b)) a a c) ((a b) a)))
;; After unforming, conforming no longer works
(->> form
(s/conform ::defn-macro)
(s/unform ::defn-macro)
(s/conform ::defn-macro)) ;;=> :clojure.spec/invalid
)