大家好,自从extend-with-metadata
协议推出以来,我们的代码库就采用了它——我们更喜欢使用映射组件而不是记录。
然而,我们的代码库和团队都是clojure spec的大用户,我们原本期待以下形式的最后一个表达式会抛出异常
(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.