您可以指定一条记录,如下所示:
(clojure.spec/def ::name string?) (clojure.spec/def ::age pos-int?) (clojure.spec/def ::occupation string?) (defrecord Person [name age occupation]) (clojure.spec/def ::person (clojure.spec/keys :req-un [::name ::age ::occupation])) (clojure.spec/valid? ::person (->Person "john doe" 25 "programmer")) ;;=> true (clojure.spec/valid? ::person (->Person "john doe" "25" "programmer")) ;;=> false
在将来的某个时候,可能会引入读取器语法或由记录的名称空间对合格记录键的内置支持。映射已经存在这种支持。