Hi Marc, note that the return of gen/sample is 10 examples. Each one is a collection.
So the collection [] matches your spec, as does [:c]. And so on. A regex-op outside of a regex-op always specs a collection. If used within another regex-op, it just specs an element. To illustrate: (gen/sample (s/gen (s/cat :kw (s/? #{:a :b :c :d})) :num number?)) ((-2.0) (:a -3.0) (0) (1) (-2.625) (:a -1) (:d -1.5625) (0.75) (:a -24) (:d -22)) Kind regards, Leon. On Saturday, January 28, 2017 at 6:29:39 PM UTC+1, Marc Wilhelm Küster wrote: > > Good afternoon, > > like obviously quite a few others on this list I am looking into the > upcoming (and IMHO absolutely great) clojure.spec > During this I noted that the ? macro seems to behave differently from > what I would have naively expected from its documentation (cf. > https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/? > ): > > ? macro > > Usage: (? pred-form) > > Returns a regex op that matches zero or one value matching > pred. Produces a single value (not a collection) if matched. > > > In contract, with the namespaces set to > [clojure.spec :as s] > [clojure.spec.gen :as gen] > > the following snippet > > (s/def ::abcd #{:a :b :c :d}) > (gen/sample (s/gen (s/? ::abcd))) > > returns a collection of collections: > ([] [:c] [:d] [:b] [:b] [] [:a] [] [:d] []) > > I would have expected to find either the value itself or nothing, a > behaviour that would seem to me also more practical when composing larger > records with optional elements. However, I might be misreading the > documentation and would be grateful for any clarification > > Best regards, > > Marc > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.