下面的示例展示了在一个已规范的表单中,在反规范后没有进一步的规范。我期望您可以重复进行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]}]}]}}
;; 反规范返回了函数定义,但参数以列表形式而不是向量形式
(->> form
(s/conform ::defn-macro)
(s/unform ::defn-macro)) ;;=> (defn foo "bar" ((a (& b)) a a c) ((a b) a)))
;; 反规范后再进行规范不再可行
(->> form
(s/conform ::defn-macro)
(s/unform ::defn-macro)
(s/conform ::defn-macro)) ;;=> :clojure.spec/invalid
)