Fork me on GitHub
#clojure-spec
<
2017-01-20
>
bbloom01:01:41

just curious: why does s/keys check the map? predicate? seems like ILookup is the minimum requirement, or am i missing something?

seancorfield01:01:28

I believe there's a JIRA issue open for that...

alexmiller03:01:08

It has to iterate through the entries so ILookup is not sufficient

bbloom03:01:25

Makes sense. I forgot about how it handles present keys even if not specified as optional.

bbloom03:01:23

One solution would be to only provide that functionality if iterable or seqable. Not sure if that's a great idea though.

joost-diepenmaat09:01:13

maybe this is a FAQ, but is there a way to automatically re-run clojure.spec/instrument after defining new functions or redefining already specced ones? I’d be fine if it would work in CIDER only.

souenzzo09:01:41

Can I use it in "production"? Or call s/conform at beginning of function? https://clojure.org/guides/spec#_instrumentation

mpenet09:01:25

instrumentation is not meant to be used in production

mpenet09:01:59

it's actually spelled out explicitly on that page

mpenet09:01:10

as for conform, yes you can

mpenet09:01:16

In production what I do is leverage :pre/:post + s/valid? in functions. and you can always turn it off with a compile time toggle. It works quite well

timgilbert14:01:06

Hey, I have a kind of polymorphic map where some keys should be present depending on the value of one of the other keys, so it's like either {:x/type :t/foo :foo/val 32} or {:x/type :t/bar :bar/baz "47"}

timgilbert14:01:57

It seems like this is difficult to describe with spec since the map specs only look at keys, not values. Am I missing something?

potetm14:01:39

If I understand right, that's what you're looking for.

timgilbert14:01:59

Aha! Exactly what I was looking for. Thanks @potetm.

viesti21:01:42

Posed a question in the general Clojure channel, but realised that I need to think about predicates that reference their environment a little more. This was the snippet that I was pondering:

user> (let [limit 100] (s/form (s/spec #(< % limit))))
(clojure.core/fn [%] (clojure.core/< % limit))

viesti21:01:53

specifically the limit in there

bbloom21:01:35

sadly, clojure’s quotations don’t capture environments

bbloom21:01:56

there’s really nothing you can do other than eager substitution

bbloom21:01:00

ie a macro

viesti21:01:38

was using s/form for unit tests on spec that I generate from data

alexmiller21:01:04

I just answered in #clojure

viesti21:01:12

thinking that the serialization thing is probably still on it’s way to clojure.spec

alexmiller21:01:40

s/form is there for that purpose (with some known bugs)

viesti21:01:51

thanks for the answer @alexmiller and sorry for posting on wrong channel 🙂

tbaldridge21:01:58

serialization with captured environments can get a bit tricky anyways.

bbloom21:01:35

it’s among the crazy ideas I’ve been studying for a number of years 😉

viesti21:01:16

was actually using s/form for unit testing specs that I generate from sql ddl statements, just toying around for now