Clojure Spec 中的“&”和“and”有什么区别?

What is the difference between `&` and `and` in Clojure Spec?

我似乎很难区分 Clojure Spec 的 &and 运算符的含义。他们似乎都做同样的事情,只有一个被标记为正则表达式运算符,我不确定我是否理解这种差异的重要性。

如果我们从中抽取一些数据,我们可以看到两者之间的区别:

(ns playground
  (:require [clojure.spec     :as spec]
            [clojure.spec.gen :as gen]))

(gen/generate (spec/gen (spec/and #{:a :c} #{:b :a :c})))
=> :a
(gen/sample (spec/gen (spec/and #{:a :c} #{:b :a :c})))
=> (:c :a :c :a :a :a :a :a :a :c)

正如我们所见,spec/and 匹配与两个谓词 #{:a :c}#{:b :a :c}.

匹配的单次出现
(gen/generate (spec/gen (spec/& #{:a :c} #{:b :a :c})))
=> [:c]
(gen/sample (spec/gen (spec/& #{:a :c} #{:b :a :c})))
=> ([:c] [:a] [:a] [:c] [:c] [:c] [:c] [:a] [:c] [:c])
另一方面,

spec/& 匹配谓词 作为序列的一部分接受的内容 .