This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-24
Channels
- # aws (14)
- # beginners (111)
- # boot (12)
- # cider (1)
- # cljsrn (7)
- # clojure (65)
- # clojure-dusseldorf (1)
- # clojure-germany (7)
- # clojure-greece (10)
- # clojure-italy (13)
- # clojure-poland (7)
- # clojure-russia (7)
- # clojure-spec (53)
- # clojure-uk (29)
- # clojurescript (27)
- # community-development (9)
- # cursive (2)
- # data-science (1)
- # datomic (17)
- # emacs (16)
- # events (6)
- # fulcro (155)
- # graphql (8)
- # instaparse (1)
- # leiningen (30)
- # lumo (29)
- # om-next (3)
- # other-languages (46)
- # pedestal (11)
- # portkey (7)
- # re-frame (13)
- # reagent (6)
- # ring (8)
- # rum (1)
- # shadow-cljs (75)
- # sql (1)
- # timbre (3)
- # unrepl (128)
I'm getting ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4744)
for a spec generator that seemingly should be fairly trivial:
(s/def ::snake-cased-alpha-numeric
(s/with-gen
(s/and string? #(re-matches #"[a-z|\_|0-9]+" %))
#(gen/fmap (fn [v] (apply str v)) (gen/vector (gen/frequency [[1 (gen/return \_)] [9 gen/char-alphanumeric]])))))
(s/def ::required? boolean?)
(s/def ::property-attrs
(s/keys :req-un [::required?]))
(s/def ::events-schema
(s/map-of integer?
(s/map-of ::snake-cased-alpha-numeric
(s/map-of ::snake-cased-alpha-numeric ::property-attrs))))
> (gen/sample (s/gen ::events-schema))
ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4744)
[I added the with-gen
on snake-cased-alpha-numeric
with it being the most complicated primitive in there and still get the error]
@johanatan can you generate any of the leaves?
> (gen/sample (s/gen ::property-attrs))
({:required? false} {:required? false} {:required? true} {:required? true} {:required? true} {:required? true} {:required? false} {:required? false} {:required? false} {:required? true})
> (gen/sample (s/gen ::required?))
(false true true false true true false true true false)
what about snake-cased? that looks like the tricky one
> (gen/sample (s/gen ::snake-cased-alpha-numeric))
("zno" "n7" "_" "3" "_" "c" "8_" "5i" "k7q" "i")
> (gen/sample (s/gen ::snake-cased-alpha-numeric) 100)
ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4744)
try (s/map-of integer? ::snake-cased-alpha-numeric)
perhaps there is a bug where my regex doesn't match values generated with the with-gen
-specified generator
i've seen that error when the two are mismatched: i.e., when the spec and the generator for it are not perfectly aligned on what is acceptable or not
@johanatan would this help? https://github.com/gfredericks/test.chuck#string-from-regex
I forget what the implications of jinx are
do I have to not talk now for some time period
I think you can't talk until someone says your name three times
the same person? back-to-back in quick succession?
aw you're right that's totally underspecified
oh wait
my mistake
Traditionally, a jinx is ended when anyone speaks the jinxed person's name. However, a common variation says that only the jinxer can free the jinxee from their obligation to remain silent. (This is sometimes called a "private jinx" or "jinx personal lock".)
a private jinx sounds a lot less interesting
there is a bug in my regex though. noticing that pipes are ending up in the output. probably was the original problem
buy me a coke I think, although I probably owe you the drink. Edit: this was about the jinxing
for ecample, I have (defn node->svg ...) and I would like to define a helper function named (defn node->svg- ...) but intuitively, functions that end in '-' seem like a bad idea
The most common convention seems to be to end in a *
@qqq I've seen that in a lot of libraries -- and started following it myself.
I have the uncommon preference for foo'
, imitating mathematical notation
that sounds like it could be a regex
though perhaps not a trivial one if you want to really follow the spec
but of course that's something somebody else has done somewhere, e.g. https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data
I'm stumbling on something pretty basic. s/cat is not working the way I'd expect.
(s/conform ::field-def [:foo :text])
=> {:field-name :foo, :field-type :text}
(s/conform (s/cat :fd ::field-def) [:foo :text])
=> {:fd {:field-name :foo, :field-type :text}}
I would have expected that to fail; ::field-def is
(s/cat :field-name keyword?
:field-type field-types)
That is, my ::field-def expects a tuple of keyword and field-type (a set of keywords). So I'd expect s/cat
to consume the first value from a list, then apply ::field-def as a predicate and deconstructor to it. Instead, it is applying ::field-def directly.
From my (mis-?) understanding, I'd expect the following to succeed, but it fails:
(s/explain (s/cat :fd ::field-def) [[:foo :text]])
In: [0] val: [:foo :text] fails spec: :com.walmartlabs.genie.launchpad.db-access/field-def at: [:fd :field-name] predicate: keyword?
:clojure.spec.alpha/spec {:clojure.spec.alpha/op :clojure.spec.alpha/pcat, :ps [:com.walmartlabs.genie.launchpad.db-access/field-def], :ret {}, :ks [:fd], :forms [:com.walmartlabs.genie.launchpad.db-access/field-def], :rep+ nil}
:clojure.spec.alpha/value [[:foo :text]]
Again, my expectation is that s/cat
consumes a seq. The first element in the seq should be a ::field-def, which itself is a seq of two elements. Instead, it is matching the treating the entire list [[:foo :text]]
as the field-def tuple, and failing because the first value in the list, [:foo :text]
is not a keyword.Basically, my goal is this:
(s/def ::primary-key (s/cat :pk-field-def ::field-def
:cluster-defs (s/* ::cluster-def)))
That is, a single field def, followed by zero or more cluster-def's.@hlship Regex specs "unwind" when they are combined, unless you wrap them in s/spec
(or some other delimiting operation).
Ok, that could be what I'm missing. It's right there in the docs, once I know what to look for!
s/cat
isn't meant for tuples -- there's s/tuple
for that
(although you'll get no labels with that I think...)
I think it catches everyone out at least once 🙂