clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
2020-05-23T07:18:34.033200Z

In your answer with with gen/one-of, you repeated keyword? which was the main predicate. In that case you repeated the main predicate twice, once for defining the validity, once in the definition of the generator. Can we avoid this repetition?

2020-05-23T07:19:29.034500Z

I think it is a common pattern to give some examples to a generator for documentation, but it reduce the power for testing.

niclasnilsson 2020-05-23T21:13:52.038300Z

Recursive specs? I’ve tried all old examples I’ve found, but they don’t seem to work (any longer?). In spec or spec2, are recursive specs possible, or is eager lookup making it impossible? I mean things like this:

(def ex '(+ (+ 1 (* 2 3)) 200))

(defn operator? [x] (#{'+ '- '* '/} x))

(s/def ::operator operator?)
(s/def ::operand int?)

;; I've tried many different ways, but fail to get something like this working
(s/def ::expr
  (s/or :operand ::operand
        :expr (s/cat :operator ::operator
                     :left ::expr
                     :right ::expr))