嗨,自从推出以来,我们的代码库已经采用了extend-with-metadata
协议,我们更喜欢映射组件而不是记录。
然而,我们的代码库和团队广泛使用了Clojure规范,并且我们原本期待以下形式的最后一个表达式会抛出错误:
(ns defproto-spec.test
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]))
(defprotocol SpecTest
:extend-via-metadata true
(delete [impl id]))
(s/fdef delete-impl
:args (s/cat :impl any? :id string?))
(defn delete-impl [_ id]
(println (str "This deletes " id))
id)
(def impl (with-meta {} {`delete delete-impl}))
(st/instrument)
(delete impl 1) ;; should throw but it doesn't
为什么我们期待它能工作呢?
也许是因为这个特性较新(1.10版)并且有以下原因:
defproto-spec.test> (st/instrument)
[defproto-spec.test/delete-me defproto-spec.test/delete-impl]
不幸的是,情况并非如此。如果其他人还没有将其纳入流程,我愿意修复这个错误并编写文档。
谢谢,
Andrea。