Fork me on GitHub
#clojure-spec
<
2017-03-09
>
ilevd10:03:39

Can I use fdef for validation in runtime? It seems it works only for :args not :ret if use instrument

jjttjj15:03:09

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

rauh15:03:31

@jjttjj I believe it's :jvm-opts ["-Dclojure.spec.compile-asserts=false"]

bbrinck16:03:59

@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

bbrinck16:03:30

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.

bbrinck16:03:13

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.

devth16:03:45

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

devth16:03:49

ah, thanks

peeja17:03:57

What's the canonical way to spec that a string matches a regex (in the #"" sense, rather than the clojure.spec sense)?

peeja17:03:54

Ah, so there is! Thanks.

bbloom21:03:09

for those folks who are attempting to meta-program specs (@nwjsmith, @tbaldridge, @ghadi), i’m very curious to hear about your use cases

bbloom21:03:18

(i love me some good metaprogramming!)

tbaldridge21:03:35

In my case, generating JSON schema (for use with swagger) from pre-defined specs.

tbaldridge21:03:57

Also, generating Datomic schemas from spec.

bbloom21:03:14

ok, so both to AND from spec use cases

tbaldridge21:03:31

Also decomposing specs into logic/datalog, so I can say "find me all ::people in this DB"

nwjsmith21:03:12

@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’ ::names. 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]) …

bbloom21:03:23

@nwjsmith what’s wrong with (s/fdef munge-name :args (s/keys :req [::name])) ?

waffletower22:03:02

I am very interested in meta-programming specs and came here to ask about spec reflection actually

waffletower22:03:43

For my application I would like to introspect on specs to dynamically create custom generators

waffletower22:03:16

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

bbloom22:03:53

so the reflection use case makes tons of sense to me - especially for doing stuff like generating docs w/ cross reference links or whatever

schmee22:03:32

can someone enlighten me: why are specs macros instead of data?

bbloom22:03:09

it’s mostly about error messages

schmee22:03:28

cause now the accepted thing to do seems to be “use form, transform that and then conform and unform” which seems backwards

bbloom22:03:29

functions don’t have enough reflective capability to provide good messages with predicate names, etc

waffletower22:03:55

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)

waffletower22:03:28

Could use another macro I guess

waffletower22:03:44

unless I am making a silly mistake I can’t see

bbloom22:03:54

i hesitate to suggest this, but....

bbloom22:03:08

eval exists on the jvm side 😛

Alex Miller (Clojure team)22:03:49

You can eval a form or use a macro

Alex Miller (Clojure team)22:03:47

The discussion in the back channel would let you start from a map and then unform with spec form specs back to a spec