Fork me on GitHub
#clojure-spec
<
2017-05-03
>
mobileink00:05:15

why do you need a macro? you're just wrapping try/catch, no?

mobileink00:05:37

i'm not an expert, but the usual advice is to avoid macros.

mobileink00:05:41

"wrap-error" strikes me as misleading. you're really just wrapping a fn, which may not have an error, no?

cfleming01:05:17

The doc seems to imply that s/alt is ordered choice, i.e. the alternatives will be tested in order and the first match returned. Is that correct?

tbaldridge02:05:29

@cfleming yes from the doc string: "Returns a regex op that returns a map entry containing the key of the first matching pred and the corresponding value. "

cfleming02:05:44

Great, thanks.

misha08:05:34

greetings! I am getting

(s/exercise :dsc/patch 1)
=> ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.  clojure.core/ex-info (core.clj:4725)
is there a way to narrow error location down? (:dsc/patch is a compound spec, ~30 lines long)

slipset09:05:47

I really wished spec was spec'ed. Just lost som time on why s/keys was valid on my invalid maps. Reason? I used :un-req instead of :req-un

misha11:05:04

is there something built in for what I'am trying to achieve (generator for next-id, which never returns a duplicate)?

misha11:05:08

how does one combine two map specs? (union)

misha11:05:57

here I'd like to avoid custom reduce-through-hashmap predicate, and combine s/keys and s/map-of specs instead

misha12:05:10

that one fails because s/and results in empty set of valid keys. s/merge will result in an empty set too. it seems like I need a custom predicate after all:

(s/def :datascript/map-with-current-tx (s/keys :req [:db/current-tx]))
(s/def :datascript/map-with-tempids-lookup (s/map-of :datascript/temp-id :datascript/actual-id))

(def gen-tempids
  (tgen/let [ids (s/gen :datascript/map-with-tempids-lookup)
             ctx (s/gen :datascript/map-with-current-tx)]
    (merge ids ctx)))

(s/def :datascript/tempids
  (s/with-gen
    (fn [m]
      (and
        (s/valid? :datascript/map-with-current-tx m)
        (s/valid? :datascript/map-with-tempids-lookup (dissoc m :db/current-tx))))
    (constantly gen-tempids)))

souenzzo12:05:58

(s/merge ::a ::b (s/keys :req[::c]) (s/map-of ,,,))

misha12:05:41

@souenzzo tried that right now. it also gives me

ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.  clojure.core/ex-info (core.clj:4725)

souenzzo12:05:42

I've never used generators. =/ But I use tons of s/merge

lwhorton12:05:19

has anyone been able to use generators with cljs? I’m not really sure how (I don’t even see gen defined in the cljs.spec.impl.gen ns, and my google foo is failing

bhagany12:05:08

@lwhorton yes, but I don't remember off the top of my head what the differences with clj were...

bhagany12:05:39

there's an example, and there's more in that project if you'd like to click around

bhagany12:05:59

tl;dr - looks like I import the clojure.test.check.generators ns, and use that in conjunction with clojure.spec/gen

lwhorton12:05:27

thanks @bhagany ill take a look

chillenious15:05:28

Hi. Trying out spec and running into a problem right away. Simply adding [clojure.spec.alpha :as s] to a :require section in my clojure file, and then trying to load that file in the repl (Leiningen) via use gives me this error: java.lang.ClassCastException: clojure.spec.alpha$regex_spec_impl$reify__1340 cannot be cast to clojure.lang.IFn When I use require instead of use, it seems fine. Anything I'm doing wrong/ known bug?

chillenious16:05:09

actually, scrap that... I get this error with either use or require whenever I pass in the :reload-all flag

seancorfield16:05:26

Yes, there’s an AOT-related issue at present with the version of spec.alpha that Clojure 1.9.0 Alpha 16 pulls in. If you explicitly depend on org.clojure/spec.alpha "0.1.108" the problem should go away.

seancorfield16:05:53

It specifically seems to affect REPL workflows and anything that reloads code.

slipset19:05:15

I’m writing specs for my om components, which basically are vararg functions of which I normally just care about the first arg.

slipset19:05:29

So I end up with something like

slipset19:05:39

(s/fdef content-area :args (s/cat :args ::grid :rest (s/* any?)))

slipset19:05:12

the :rest (s/* any?) bit seems a bit silly.