This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-18
Channels
- # aws-lambda (3)
- # beginners (57)
- # boot (3)
- # bristol-clojurians (1)
- # cider (38)
- # cljs-dev (23)
- # clojure (35)
- # clojure-italy (32)
- # clojure-nl (6)
- # clojure-spec (35)
- # clojure-uk (132)
- # clojurescript (34)
- # cursive (22)
- # data-science (1)
- # datomic (54)
- # devcards (1)
- # duct (5)
- # editors (7)
- # euroclojure (4)
- # fulcro (40)
- # graphql (1)
- # hoplon (6)
- # immutant (5)
- # jobs (1)
- # off-topic (22)
- # om (1)
- # planck (17)
- # portkey (1)
- # protorepl (12)
- # re-frame (97)
- # reagent (67)
- # reitit (16)
- # ring-swagger (1)
- # shadow-cljs (98)
- # spacemacs (8)
- # sql (20)
- # tools-deps (60)
Hi. I've noticed that CLJS impl of explain
prints more stuff than Clojure. Is it on purpose?
CLJS:
=> (s/explain ::x 23)
val: 23 fails spec: :cljs.user/x predicate: string?
:cljs.spec.alpha/spec :cljs.user/x
:cljs.spec.alpha/value 23
Clojure:
=> (s/explain ::x 23)
val: 23 fails spec: :cljs.user/x predicate: string?
If I would like instrument
to check my specs, what would be the preferred way of spec:ing a multimethod? Can I use a multispec with the same dispatch fn or do I need an indirection fn with a spec in each defmethod
?
You can make the defmulti dispatch function explicit and spec that
In my case each defmethod
gets called with a map and the map should have different contents for each method. As I read your answer it would be the same spec for all methods?
@kenny I wonder if qualified symbols can be replaced like this:
(case form-sym
(clojure.spec.alpha/keys
cljs.spec.alpha/keys) ...
;=>
(case form-sym
`s/keys ...
I recall that spec was inspired in part by RDF. Is there any recommended way for describing XML structures?
xml represented by what data structure?
Its sexp-as-element
is the closest I've seen it get to simple data structures, but even that seems to be pretty complex to spec
seems pretty straightforward?
there are at least two formats there - the input and output of sexp-as-element. they both seem pretty straightforward to spec if you want to
Element is a defrecord, so you can just spec it as a map with 3 known keys
the sexp form is just structured vectors and can be spec’ed with s/cat etc
oh, there actually are specs already in data.xml
https://github.com/clojure/data.xml/blob/master/src/main/resources/clojure/data/xml/spec.cljc
that’s for the element forms
if I want to declare a with-gen ::spec generator-fn
, generator fn needs to be a fn that returns a generator. how does one create a generator that’s simply a function, without using fmap or any of the other test.check.generators?
for example I just want a “generator” that invokes (random-uuid)
where the fn itself is already random and doesn’t need any randomness from the generator scaffolding
i had some garbage like
(s/exercise ::p/id 10 {::p/id (fn [] (gen/fmap #(random-uuid) (s/gen (s/int-in 1 10))))})
but this is abusing fmap to just give me access to a fn I can call that will return a value that’s wrapped in the proper generatorhttps://clojure.github.io/test.check/generator-examples.html
(def int-or-nil (gen/one-of [gen/int (gen/return nil)]))
(gen/sample int-or-nil)
;; => (nil 0 -2 nil nil 3 nil nil 4 2)
that seems like the same idea as abusing fmap and an existing gen (int-in), but with different fns. it just feels like there’s a built-in fn like gen/return
for this use case, right?
using external sources of randomness prevents shrinking and repeatability so is discouraged
if you want to do the discouraged thing, fmap
will work and return
won't.