Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure “的表达方式;“集合中的成员”;有着丰富的图式_Clojure_Plumatic Schema - Fatal编程技术网

Clojure “的表达方式;“集合中的成员”;有着丰富的图式

Clojure “的表达方式;“集合中的成员”;有着丰富的图式,clojure,plumatic-schema,Clojure,Plumatic Schema,我想写一个模式,其中数据结构中的元素e可以是一组项中的任意成员;E∈ 美国的Clojure规范使用如下集合表示: (spec/def ::key-set #{:subprocess :leiningen :nrepl}) (gen/sample (spec/gen ::key-set)) ; => (:nrepl :subprocess :subprocess :leiningen :subprocess :nrepl :subprocess :leiningen :nrepl :subp

我想写一个模式,其中数据结构中的元素e可以是一组项中的任意成员;E∈ 美国的Clojure规范使用如下集合表示:

(spec/def ::key-set #{:subprocess :leiningen :nrepl})
(gen/sample (spec/gen ::key-set))
; => (:nrepl :subprocess :subprocess :leiningen :subprocess :nrepl :subprocess :leiningen :nrepl :subprocess)
对于一组关键字


然而,在模式中,集合用于表示一组事物,而不是集合中的一个元素成员。那么,我如何在模式中表示我想要一个集合中的一个成员呢

user=> (schema.core/validate (schema.core/enum "a" "b" "c") "a")
"a"

=> (schema.core/validate (schema.core/enum "a" "b" "c") "z")
clojure.lang.ExceptionInfo: Value does not match schema: (not (#{"a" "b" "c"} "z"))

schema.core/enum
就是您要寻找的

user=> (schema.core/validate (schema.core/enum "a" "b" "c") "a")
"a"

=> (schema.core/validate (schema.core/enum "a" "b" "c") "z")
clojure.lang.ExceptionInfo: Value does not match schema: (not (#{"a" "b" "c"} "z"))