Fork me on GitHub
#clojure-spec
<
2016-07-28
>
mpenet07:07:09

@gfredericks: chuck.gen/string-from-regex is nothing short of magic, impressive

stammi09:07:48

Hi! Maybe someone can spot my mistake in this:

stammi09:07:51

(s/def ::number-between-one-and-zero (s/and number? #(< % 1) #(> % 0)))

stammi09:07:59

(s/conform ::number-between-one-and-zero "-13")

stammi09:07:10

gives me valid

stammi09:07:22

oh forget that please...

Alex Miller (Clojure team)12:07:05

Check out s/int-in or s/double-in

mike_ananev13:07:49

hi! if i have (s/def ::decimal #(instance? BigDecimal %)) how to make (s/exercise ::decimal) working? I suppose a should create custom generator in spec, but can't find how to do it. thanx

mpenet13:07:58

I guess something like (gen/fmap #(BigDecimal. %) gen/nat)

mpenet13:07:45

(s/def :decimal (s/spec #(...) :gen (constantly (gen/fmap #(BigDecimal. %) gen/nat)))) (untested)

mike_ananev14:07:26

@mpenet: 😞 doesn't work. I've tried similar ways and unfortunately can't get result. i'm dumb :((

mpenet14:07:58

seems to work here

mpenet14:07:13

(s/def ::decimal (s/spec #(instance? BigDecimal %)
                         :gen (constantly (gen/fmap #(BigDecimal. %) gen/nat))))

mpenet14:07:37

exercise returns -> ([0M 0M] [0M 0M] [1M 1M] [2M 2M] [1M 1M] [0M 0M] [4M 4M] [1M 1M] [2M 2M] [5M 5M])

mpenet14:07:21

well, you need to throw in the decimal part actually ex (str % ".0")

mpenet14:07:50

you could generate pairs for the part after .

mike_ananev14:07:15

thanx. can you show your gen namespace from require section?

mpenet14:07:35

gen is clojure.test.check.generators

gfredericks14:07:07

Maybe it's a good time to get a good bigdec and bigint and ratio generator in test.check

mpenet14:07:19

there is ratio I think, not big* tho

mike_ananev14:07:08

have trioubles with gen namespace

mike_ananev14:07:09

Alias gen already exists in namespace arina-aaa.atomix.spec, aliasing clojure.spec.gen

mike_ananev14:07:18

(:require [clojure.spec :as s] [clojure.test.check.generators :as gen])

mike_ananev14:07:44

Ah! REPL restart helps!

mpenet14:07:56

🙇

gfredericks14:07:27

Oh right. I meant a good ratio generator :)

michaeldrogalis15:07:30

I'm a little caught up on s/def being a macro. Is it possible to do something like:

(let [x :my/spec-name]
  (s/def x string?))

michaeldrogalis15:07:09

The problem seems to be that def expands, and the first argument retains the value of the symbol x, not the value that it refers to (`:my/spec-name`)

featalion16:07:40

you can do it with another macro:

(let [x :user/the-x]
  `(s/def ~x string?))
;;=> (clojure.spec/def :user/the-x clojure.core/string?)

stammi17:07:51

thanks @alexmiller. that looks better indeed