Fork me on GitHub

Hello, I am trying to spec some higher order functions using fdef and fspec For eg:

(s/fdef adder
  :args (s/cat :x number?)
  :ret (s/fspec :args (s/cat :y number?)
                :ret number?)
  :fn #(= (-> % :args :x) ((:ret %) 0)))
is it possible to get the value of argument x inside the spec of the inner function which is returned ?


Hello there! Quick question: is it possible to create an "inline" s/keys inside a s/cat in fdefs? Like:

(s/fdef something :args (s/cat :first-argument (s/keys :req-un [::a ::b ::c])))


😞 Ok, thank you!

Alex Miller (Clojure team)14:09:08

or wait, maybe? what are you trying to do?

Alex Miller (Clojure team)14:09:40

if you’re matching varargs in a function


Hmmm, I'll check that out 😃

Alex Miller (Clojure team)14:09:19

and even my prior answer is wrong - you can use s/keys there (I just don’t think it’s what you want)

Alex Miller (Clojure team)14:09:45

are you taking a map or a series of key/value options in something?


Odd; I tried that way before and my generative test exploded


I'm taking a map

Alex Miller (Clojure team)14:09:08

oh, then you should be fine with the above

Alex Miller (Clojure team)14:09:57

if you want to test it, run (s/exercise (s/cat :first-argument (s/keys :req-un [::a ::b ::c])) 1000) - that’s basically what you’re getting with a generative test on something


Nice catch, I'll inspect this way

Alex Miller (Clojure team)14:09:01

often pushing that out to 1000 samples reveals more :)

Alex Miller (Clojure team)14:09:33

if a/b/c are big colls, that can provoke some problematic samples - bounding their size often helps


Actually that's not the case, in my scenario ::a, ::b and ::c are just very specific definitions, but I got your point


are there any projects for associating docstrings with spec definitions?

Alex Miller (Clojure team)18:09:54

we will eventually get around to implementing it in spec, just kinda far down the list atm