This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-09
Channels
- # beginners (22)
- # boot (80)
- # cider (6)
- # cljs-dev (5)
- # clojure (190)
- # clojure-berlin (5)
- # clojure-dev (24)
- # clojure-italy (14)
- # clojure-russia (70)
- # clojure-spec (39)
- # clojure-uk (82)
- # clojurescript (121)
- # clojurewest (1)
- # core-logic (2)
- # cursive (25)
- # datascript (186)
- # datomic (33)
- # dirac (266)
- # emacs (9)
- # gsoc (4)
- # hoplon (37)
- # immutant (34)
- # instaparse (22)
- # jobs (4)
- # juxt (6)
- # lambdaisland (2)
- # leiningen (1)
- # liberator (1)
- # luminus (5)
- # lumo (28)
- # off-topic (9)
- # om (23)
- # onyx (26)
- # other-lisps (1)
- # parinfer (39)
- # pedestal (45)
- # proton (1)
- # protorepl (10)
- # re-frame (18)
- # reagent (4)
- # ring-swagger (8)
- # rum (4)
- # specter (13)
- # test-check (14)
- # testing (1)
- # unrepl (164)
- # untangled (10)
- # yada (14)
Can I use fdef
for validation in runtime? It seems it works only for :args
not :ret
if use instrument
Is there an easy way to disable clojure.spec assertions thoughout a lein project? Right now I have
:global-vars {*assert* false
clojure.spec.compile-asserts false
}
in project.clj but it's not working@ilevd Instrumentation only checks :args
, not :ret
or :fn
. It’s a common point of confusion. :ret
and :fn
specs are only with generative tests
I’d personally prefer if instrument
checked ret
and fn
(at least optionally), but the authors of spec would say that the point of instrument
is to check that you are calling the function correctly, whereas the point of generative testing is to ensure it is implemented correctly.
In my experience, this means that I often don’t write ret
or fn
specs for functions that can’t be tested with generative testing, which is a shame, because I miss out on the documentation benefits of spec for these functions.
any way to remove from the registry-ref
atom? not seeing a way to get at it in https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj
What's the canonical way to spec that a string matches a regex (in the #""
sense, rather than the clojure.spec
sense)?
there is an email example in the guide https://clojure.org/guides/spec
for those folks who are attempting to meta-program specs (@nwjsmith, @tbaldridge, @ghadi), i’m very curious to hear about your use cases
In my case, generating JSON schema (for use with swagger) from pre-defined specs.
Also, generating Datomic schemas from spec.
Also decomposing specs into logic/datalog, so I can say "find me all ::people in this DB"
@bbloom here’s an example that @peeja came up with at work yesterday: I want to have a spec for an entity map (e.g. (s/def ::widget (s/keys :req [::id ::name]))
). Let’s say I only have a function that deals with entities’ ::name
s. It’d be nice to take the ::widget
spec and make it’s ::id
into an :opt
key. So that the name-handling fn’s spec could be (s/fdef munge-name :args (req-only ::widget [::name]) …
I am very interested in meta-programming specs and came here to ask about spec reflection actually
For my application I would like to introspect on specs to dynamically create custom generators
As far as reflection I didn’t get past this:
user> (s/def ::museum string?)
:user/museum
user> (def as (s/keys :req [::museum]))
#'user/as
user> (type as)
clojure.spec$map_spec_impl$reify__13776
user> (pprint as)
#object[clojure.spec$map_spec_impl$reify__13776 0x10475684 "clojure.spec$map_spec_impl$reify__13776@10475684"]
nil
@waffletower use s/form
many thanks!
so the reflection use case makes tons of sense to me - especially for doing stuff like generating docs w/ cross reference links or whatever
cause now the accepted thing to do seems to be “use form
, transform that and then conform
and unform
” which seems backwards
functions don’t have enough reflective capability to provide good messages with predicate names, etc
I am interested in programmatically generating specs, and my simple example caused the s/keys macro to throw:
(def as-req [::museum])
#'user/as-req
user> (def as (s/keys :req as-req))
CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol, compiling:(*cider-repl fulfill*:253:15)
user> (macroexpand '(s/keys :req as-req))
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol clojure.lang.RT.seqFrom (RT.java:547)
Could use another macro I guess
unless I am making a silly mistake I can’t see
@waffletower this won't work right now
You can eval a form or use a macro
Thanks Alex
The discussion in the back channel would let you start from a map and then unform with spec form specs back to a spec