This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-20
Channels
- # announcements (1)
- # beginners (164)
- # calva (70)
- # cider (26)
- # cljs-dev (6)
- # cljsrn (1)
- # clojars (3)
- # clojure (123)
- # clojure-berlin (1)
- # clojure-dev (5)
- # clojure-ecuador (9)
- # clojure-europe (2)
- # clojure-italy (14)
- # clojure-nl (21)
- # clojure-nlp (5)
- # clojure-portugal (1)
- # clojure-spain (3)
- # clojure-spec (26)
- # clojure-uk (47)
- # clojurescript (17)
- # clr (1)
- # code-reviews (7)
- # core-async (5)
- # cursive (8)
- # data-science (2)
- # datomic (28)
- # emacs (23)
- # events (1)
- # fulcro (43)
- # graalvm (6)
- # graphql (8)
- # immutant (5)
- # jackdaw (17)
- # jobs (1)
- # jobs-discuss (20)
- # joker (3)
- # leiningen (8)
- # luminus (12)
- # off-topic (61)
- # overtone (5)
- # pathom (2)
- # quil (1)
- # re-frame (15)
- # reagent (2)
- # reitit (23)
- # remote-jobs (1)
- # schema (1)
- # shadow-cljs (26)
- # tools-deps (56)
- # vim (4)
I am calling generate
on a complex data structure.
Sometimes I see this error.
I would normally troubleshoot this by commenting out parts of the spec to zone in on the problem; but I'm wondering if there is a smarter way to debug generators
is there a direct way to dicover the specific sub-spec that has the problem?
okay another question;
I want a generator that has two modes of operation
• when there is data available in the dynamc variable *existing-ids*
then I want it to behave like (element *existing-ids
)`
• when *existing-ids*
is empty then I want it to behave like (spec/gen string?)
this must be a fairly common use case
how has it been solved before?
I'm thinking something like
(test.gen/bind
(test.gen/return nil)
(fn [_]
(if (not-empty *existing-ids*)
(test.gen/elements *existing-ids*)
test.gen/string-alpha-numeric)))
that doesn't seem a very smart solution though
I think that's the best I can do, unless I hack directly into
(defn- bind-helper
or
(defn- make-gen
but that doesn't seem like a very good idea either(def ^:dynamic *existing-ids* nil)
=> #'dev/*existing-ids*
(def gg (test.gen/bind
(test.gen/return nil)
(fn [_] (if (not-empty *existing-ids*)
(test.gen/elements *existing-ids*)
test.gen/string-alphanumeric))))
=> #'dev/gg
(spec.gen/generate gg)
=> "9Dlv2SuFqT4Jb"
(binding [*existing-ids* [:this :that :tother]]
(spec.gen/generate gg))
=> :that
I suppose I could store the test.gen/elements
in the *existing-ids*
var
(spec/with-gen
takes a gen-fn, and I'd hope that I could use this to choose between generators, but of course it doesn't get called very often
this might be better actually
(defn build-indirect-gen
[vargen]
(test.gen/bind
(test.gen/return nil)
(fn [_] (deref vargen))))
(def ^:dynamic *existingids-gen* test.gen/string-alphanumeric)
(def gg (build-indirect-gen #'*existingids-gen*))
(binding [*existingids-gen* (test.gen/elements [:this :that])]
(test.gen/generate gg))
=> :that
(test.gen/generate gg)
=> "Sjeu5IwBWbMUZl"
@ben.hammond afair, Gary touched on it debugging "Couldn't satisfy such-that predicate after 100 tries" here: https://www.youtube.com/watch?v=F4VZPxLZUdA
I've not seen that video. that's very interesting
i'd not seen the size/scale explained properly before
I'd assumed they represented mean/standard deviation
I'm sure this has been asked and answered, but I can't find the answer... Why can I not do the following?
(s/def ::a any?)
(s/def ::thing (let [ks [::a]] (s/keys :req ks)))
That yields Don't know how to create Iseq from: clojure.lang.Symbol
.I'm guessing that macros are the only way to dynamically define specs?
I think spec2 has some improvements to this, but still isn't going to let you plop a let
in there
I think spec2 will expose a public ast-like interface for programmatic spec creation/manipulation of specs as data
Hmm, alright. I'm interested in the spec2 feature you mentioned so I'll take a look. Thanks!
Spec 2 has a macro layer and a function layer that implements the macros. You can programmatically construct pretty much any spec in Spec 2.
(we have a branch of our code base at work that uses Spec 2 -- so we can track the sort of differences we'll need to make when we transition from Spec 1)
Ah, that's exciting!