Fork me on GitHub
#clojure-spec
<
2016-10-20
>
Alex Miller (Clojure team)02:10:41

s/def updates the registry so that needs to occur before you can use the spec

mpenet09:10:29

how do you wrap a function that returns values to be used as gen that don't depend and randomisation at test.check level (it's an external lib that already does this (sentence generation))

mpenet09:10:17

I know I can (gen/fmap (fn [_] (some-lib/foo)) (gen/any)) but that seems a bit too convoluted

mpenet11:10:12

I don't think so gen/return will always return the same value

Alex Miller (Clojure team)11:10:45

The fact that foo doesn't rely on test.checks notions of randomness is actually a problem (as it can't play in growing, shrinking, or creating reproducible results)

mpenet11:10:14

I know it's a bit "dirty"

Alex Miller (Clojure team)11:10:17

But I think you could also use gen/bind to do this

mpenet11:10:32

bind is from generator to generator, I am not sure this works too

Alex Miller (Clojure team)11:10:05

Yeah, I'm thinking of it as a gen

mpenet11:10:45

I am not sure I understand, you have an example?

Alex Miller (Clojure team)11:10:27

I guess its not any better than what you had with fmap

Alex Miller (Clojure team)11:10:27

I mean you could directly satisfy the test.check requirements to be a generator

Alex Miller (Clojure team)11:10:44

I think it's just a record with a function field

mpenet11:10:31

yep I saw that too, but it's almost the same as the fmap solution in the end

mpenet11:10:36

it's a 2 arg func

mpenet11:10:59

doesn't feel right to use it either, the "make-gen" function is private for instance

Alex Miller (Clojure team)11:10:32

Well you're starting from the position of doing something you shouldn't :)

Alex Miller (Clojure team)11:10:52

So it's going to feel wrong whatever you do

mpenet11:10:55

it's probably not an uncommon need tho

Alex Miller (Clojure team)11:10:08

First time I've seen it asked

mpenet11:10:19

but I can live with the "hack" for now

Alex Miller (Clojure team)11:10:57

Since you're not going to use the value, I'd pick a simpler generator than any?

Alex Miller (Clojure team)11:10:08

If you're doing the fmap one

mpenet11:10:31

or even (gen/return nil)

mpenet11:10:41

but it doesn't make much diff

mpenet12:10:32

is there a way to increase "randomness" of num generators in test.gen?

mpenet12:10:46

it's often just +-1

mpenet12:10:03

well, I guess it's just a matter of gen size actually

odinodin12:10:56

Does anyone have any tips on how to use clojure.spec/keys on Datomic entities? Looking for a workaround for the following http://dev.clojure.org/jira/browse/CLJ-2041

Alex Miller (Clojure team)12:10:33

I don't know that there is a solution to 2041 btw

odinodin12:10:11

currently hurting us bad, since we work with entities all over, treating them as maps

Alex Miller (Clojure team)12:10:44

The lighter weight lookup interfaces do not have a way to iterate over entries which keys needs to do

Alex Miller (Clojure team)12:10:31

I know this has been discussed re Datomic but I'm not sure where things will end up

odinodin12:10:31

right, also guess conform would call assoc as well

liamd21:10:04

is there a spec equivalent of annotating types using the s/defn, etc. macros in schema with :- and all that?

liamd21:10:54

or do i just use fdef

liamd21:10:31

also, so the name of a spec is a key that corresponds to what it must be called in a map, but also is just the name of a thing if you’re using it not in a map?

liamd21:10:43

so how do i spec a map where the keys are strings?

jasonjckn21:10:35

use conformer

bfabry22:10:17

@liamd s/keys requires keyword keys for validating maps. if you don't have keyword keys, you'll need to use map-of, coll-of, custom predicates etc

bfabry22:10:29

and yes, use fdef

jasonjckn23:10:10

one of my dependencies is broken ""call to clojure.core/defn did not conform to spec""

jasonjckn23:10:17

is there a way to disable spec checks?

seancorfield23:10:36

Most of the libraries "broken" by recent spec versions have already released new versions. What is breaking?

jasonjckn23:10:09

a few different deps, i'm trying to upgrade them now, i'll let you know if it's still broken

jasonjckn23:10:27

also fyi the error mesasge makes it very hard to know who the culprit is

seancorfield23:10:41

(and what releases have fixes)

seancorfield23:10:15

I would have expected the error to fairly clearly indicate the source file containing the illegal defn?

seancorfield23:10:41

Current version is 3.1.0

seancorfield23:10:19

The problem is the format of :or [auto-connect-retry true] which should be :or {auto-connect-retry true}

seancorfield23:10:36

Looks like it was reported in early June and fixed in mid-August https://github.com/michaelklishin/monger/issues/142

seancorfield23:10:07

So, yeah, you’ll need a newer version of Monger than 3.0.2 @jasonjckn

jasonjckn23:10:17

kk, thanks sean

seancorfield23:10:24

I updated http://dev.clojure.org/display/design/Errors+found+with+core+specs to show 3.1.0 contains the fix for Monger 3.0.2’s breakage.