Fork me on GitHub
#clojure-spec
<
2016-12-01
>
stathissideris00:12:02

hello, do function specs and other specs end up in different parts of the registry?

stathissideris00:12:12

for example, I have a call like that: (foo {::foo 1})

stathissideris00:12:40

can I safely do (s/def ::foo integer?) and (s/fdef ::foo …)

Alex Miller (Clojure team)00:12:01

No, those will collide (and the fdef will not be used)

Alex Miller (Clojure team)00:12:46

Def puts keyword keys in the registry and fdef puts symbol keys in the registry

stathissideris00:12:03

oh so my example should really be (s/fdef foo …) instead, in which case no collision

stathissideris00:12:23

I have another one: is there a shorter form for (let [{:keys [::stats/foo ::stats/bar]} {::stats/foo 2}] foo)

stathissideris00:12:42

@alexmiller btw, I enjoyed your interview for the defn podcast, quite intriguing (all the stuff about secret future plans for clojure)

Alex Miller (Clojure team)00:12:10

Do ::stats/keys [foo bar]

clojuregeek01:12:34

Live stream from AustinClojure meeting by Stu on spec https://m.youtube.com/watch?v=dQcNAscSTSw

bbloom03:12:50

i’m totally blown away by how i have a namespace with > 100 defns, only 4 fundamental ones of which have specs, and they help me catch tons of errors - super nice

bbloom03:12:15

the return value of instrument reminds me of just how little spec you actually need to get some value from it

bbloom03:12:23

vs mandatory type checking everywhere

naomarik05:12:35

the official spec guide is very well written, had no issues consuming it to once for deep comprehension and also been able to quickly scan it for answers

naomarik05:12:45

just want to say thanks for that effort 😉

mishadoff09:12:22

Hey, I experienced an issue in clojure.spec where :fn key in fdef is ignored (clojure 1.9-alpha14) Here is MVP demonstrating the problem.

(defn add [x y]
  #_(+ x y)
  2)

(s/fdef add
        :args (s/cat :x number? :y number?)
        :ret number?
        :fn #(= (+ (-> % :args :x)
                   (-> % :args :y)) (:ret %)))

(clojure.spec.test/instrument `add)
If I call (add 1 nil) I got spec error, but when I call (add 1 2) spec says everything is ok, despite the fact add always returns 2 Can anybody help me?

joost-diepenmaat10:12:19

@mishadoff AFAICT instrument only checks :args (and apparently not :ret or :fn)

joost-diepenmaat10:12:53

this is surprising to me too but that’s how it’s documented:

joost-diepenmaat10:12:11

from the instrument docstring

pithyless10:12:41

@mishadoff @joost-diepenmaat - this has got to be FAQ #1 on clojure-spec 🙂 clojure.spec.test/instrument will only check :args (it’s meant to throw errors if you are using the function incorrectly); clojure.spec.test/check will run generative tests and check that the function is implemented correctly.

mishadoff10:12:24

Strange, but.. Thanks 🙂

ikitommi13:12:54

Blogged about Schema & Clojure Spec for Web Developers. http://www.metosin.fi/blog/schema-spec-web-devs/ hopefully everyone's spec lib got mentioned.

nha14:12:18

@ikitommi the link to yada is wrong. Nice article 🙂

ikitommi15:12:31

@nha thanks! fixed the link.

camdez15:12:23

Well, I decided to finally give spec a whirl, moved to 1.9.0-alpha14, and promptly discovered that I can’t get a REPL running because one of my dependencies has a non-conforming defn. 😒 Anything I can do here short of replacing / removing the (slightly busted) library?

Alex Miller (Clojure team)15:12:26

Most offending libs have newer versions that fix these problems

camdez15:12:06

@alexmiller: I’m aware—you actually patched the library in question 😄 (Aleph). But a new release hasn’t been cut yet.

camdez15:12:20

But I’m curious conceptually what the options are here.

camdez15:12:40

Certainly I can cut my own release.

Alex Miller (Clojure team)15:12:54

You could s/fdef a dummy spec over the defn spec

Alex Miller (Clojure team)15:12:15

But might be tricky to get that loaded at the right time

camdez15:12:18

@alexmiller: Gotcha. But I’d basically be overriding it globally, right?

camdez15:12:26

For all defns

camdez15:12:44

k. Thanks.

camdez15:12:43

Ah, my mistake—there is an alpha release of Aleph with a conforming defn. (Didn’t release lein ancient wouldn’t show that.)

bbloom23:12:32

i saw some discussion yesterday about docstrings

bbloom23:12:36

would be super nice to have some mechanism for that

bbloom23:12:45

i’ve got some metadata on some objects that i’d like to document better than with a comment

Alex Miller (Clojure team)23:12:00

There is not an obvious place to hang it atm, but there are some options

bbloom23:12:15

syntax: the cause of and solution to all of our problems

Alex Miller (Clojure team)23:12:22

I don't mean syntax, I mean where to remember it

Alex Miller (Clojure team)23:12:53

Could be easily added to s/def

bbloom23:12:18

oh - i thought the (a?) challenge was no metadata on keywords

Alex Miller (Clojure team)23:12:58

You don't have to provide it as metadata (or store it as metadata)