Fork me on GitHub

Hey, I was wondering if there was a shorthand for creating fdefs , For example I have:

(s/fdef new-person
  :args (s/cat :name :person/name
               :age :person/age)
  :ret :app/person)
(defn new-person [name age]
  {:person/name name
   :person/age age})
Which works, but it’s quite a lot noise (seeing that the fdef is larger than the function itself I know I shouldn’t be comparing spec to type signatures, but that’s basically what I’m doing here. Something like this would be pretty useful for me:
(s/sig new-person [:person/name :person/age] :app/person)
(defn new-person [name age]
  {:person/name name
   :person/age age})


I think I’ve seen a few libraries that have macros combining defn and fn specs


Thanks, these sort of do what I want. But they replace defn which I don’t like. I couldn’t find anything so I ended up writing a quick macro:

(defmacro defsig
  [fname fargs fret]
  `(clojure.spec.alpha/fdef ~fname
     :args (clojure.spec.alpha/cat [email protected](apply concat (map vector (map (comp keyword str) (range)) fargs)))
     :ret ~fret))

Alex Miller (Clojure team)13:12:10

Stay tuned for spec 2.... :)


Looking forward to that!

Alex Miller (Clojure team)16:12:55

Rich is working on the design for this right now and it’s starting to look pretty good

👏 32
parrot 8

I'd be interested to hear what your workflow (feedback loop?) is for developing the language. Are there any blogs about that?

Alex Miller (Clojure team)14:12:16

I did a talk at Clojutre that talks about it some


in your Nice and Accurate Counsel?


That would be such an amazing improvement for me. I’d honestly want to spec every function at my day job (I guess that’s the static typing mindset in my head talking), but it’s just too verbose at the moment


it’s also difficult to convince my colleagues 😄