嗨,自从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。