This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-25
Channels
- # aleph (12)
- # announcements (2)
- # beginners (40)
- # calva (8)
- # cider (26)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (122)
- # clojure-dev (9)
- # clojure-europe (2)
- # clojure-nl (2)
- # clojure-spec (42)
- # clojure-uk (20)
- # clojurescript (86)
- # cursive (15)
- # data-science (1)
- # datomic (42)
- # duct (4)
- # emacs (33)
- # events (1)
- # figwheel-main (2)
- # fulcro (33)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (13)
- # leiningen (9)
- # off-topic (62)
- # pathom (75)
- # quil (2)
- # re-frame (6)
- # reagent (13)
- # reitit (3)
- # shadow-cljs (52)
- # spacemacs (3)
- # specter (17)
- # sql (6)
- # tools-deps (2)
- # vim (3)
- # yada (28)
@alexmiller left a few comments about the new SHA here https://github.com/borkdude/speculative/issues/124#issuecomment-457532789 and here https://github.com/borkdude/speculative/issues/124#issuecomment-457533593
I've just started playing with
.
I can see that the :args
are getting verified, but I cannot see how to get the :ret
verified
this is the code that I pinched from https://blog.taylorwood.io/2017/10/15/fspec.html
(defn digits
"Takes just an int and returns the set of its digit characters."
[just-an-int]
(into #{} (str just-an-int)))
=> #'dev/digits
(s/fdef digits
:args (s/cat :just-an-int int?)
:ret (s/coll-of char? :kind set? :min-count 1))
=> dev/digits
(spec.test/instrument `digits)
=> [dev/digits]
(digits 1)
=> #{\1}
(digits "1")
Execution error - invalid arguments to dev/digits at (form-init1603011188380229902.clj:1).
"1" - failed: int? at: [:just-an-int]
so far so good; now I want to modify the :ret
to something impossible and retest
(s/fdef digits
:args (s/cat :just-an-int int?)
:ret (s/coll-of keyword? :kind set? :min-count 1))
=> dev/digits
(digits 1)
=> #{\1}
Hmm I was expecting the return value to fail. I can see the change in the doc string
(doc digits)
-------------------------
dev/digits
([just-an-int])
Takes just an int and returns the set of its digit characters.
Spec
args: (cat :just-an-int int?)
ret: (coll-of keyword? :min-count 1 :kind set?)
=> nil
what do I need to do to get the :ret
spec verified?
@ben.hammond ret is not checked during instrumentation
is that a feature? or a bug?
okay, so I have to manually call (spec/conform
that's not a biggie
Thanks
@ben.hammond this library can help you with checking examples: https://github.com/borkdude/respeced/blob/master/README.md#check-call
Well I was just trying to pace out my basic understanding don't need to get too fancy at this point
thanks
is there a good predicate for checking if x
can be used as a spec?
should be true for int?
, (spec/spec ...), #{1 2 3}
(doc spec/def)
-------------------------
clojure.spec.alpha/def
([k spec-form])
Macro
Given a namespace-qualified keyword or resolvable symbol k, and a
spec, spec-name, predicate or regex-op makes an entry in the
registry mapping k to the spec. Use nil to remove an entry in
the registry for k.
=> nil
any predicate should be fine
(which will include int?
and hashsets)
or the keyword identifier of an existing spec
or an inline spec declaration
by 'regex-op` I think they mean combinations of (spec/+
, (spec/cat
, ,(spec/alt` etc..?
how do you tell if an arbritary function is a predicate? I'm not sure if you can distinguish function arity from the outside
other than by provoking ArityExceptions
I guess you could get java.lang.reflect
to tell you
and there is probably a clojurey wrapping somewhere
@vemv you want a predicate that tells you if a thing fits inside (s/fdef x --> ? <--)
?
keep in mind that all of these answers will be different in spec2 :)