Fork me on GitHub

Can you please point me what I’m doing wrong in example below:

(defn command [m] 1)
(s/fdef command
        :args (s/cat :n int?)
        :ret string?)
(command "ff") ;; => 1
It works and is not failing with exception


ah, you’re right. Sorry for dumb question


also, remember that the return value is not checked even if you instrument it.

Alex Miller (Clojure team)19:05:02

The :ret spec is checked only by stest/check


You can also use Orchestra to instrument your spec return values:


One more newbie question about spec. here as example

{:email1 ""
 :email2 ""
 :email3 ""
 :email4 ""
 :email5 ""
 :data 1112}
Here is spec I wrote, anyway to make it shorter?
(s/def ::email1 string?)
(s/def ::email2 string?)
(s/def ::email3 string?)
(s/def ::email4 string?)
(s/def ::email5 string?)
(s/def ::data int?)
(s/def ::item
  (s/keys :req-un [::email1 ::email2 ::email3 ::email4 ::email5 ::data]))


rmuslimov: Seems like you’re missing a few colons in s/keys.


yep, fixed. but question remain the same. Why spec is longer than data? is it supposed to be like that? Or it’s my un-optimized solution?

Alex Miller (Clojure team)21:05:01

it’s supposed to be like that.


Would it be dangerous for a user to create a macro for that? like (sdef-each seq-of-keys string?)


rgr. so, @U0AR40HJ6, it's possible, bit it's definitely not a newbie/beginner level answer, if you're new to the language in general.


@U050PJ2EU I can do a macro, was just wondering if there exist any proper way to that. thanks!


No prob. Might want to consider using the long form though, from a user/documentation perspective.


If core comes out with such a function in the future, then you can rely on your downstream users to know what you're talking about (if that's a factor for you)

Alex Miller (Clojure team)21:05:37

not going to add that to core


right, so if you are making a library you expect to be consumed by others, remember that spec is also intended to be used for documentation.

Alex Miller (Clojure team)21:05:55

if you’re just wrapping calls to s/def, I don’t see how that matters

Alex Miller (Clojure team)21:05:20

there will be no difference between doing it explicitly or doing it in a macro?

Alex Miller (Clojure team)21:05:46

the macro would presumably just unroll to the same set of calls


@U064X3EF3 so any documentation functions that operate on sources will probably operate post macro-expansion?


(Or whatever documentation features are expected to work with spec in the future)

Alex Miller (Clojure team)21:05:37

doc functions don’t use the sources for specs

Alex Miller (Clojure team)21:05:50

docs look up the specs in the registry


macro away then 🙂


Why not a vec ::emails with 5 string elements? :thinking_face:


not that i know of. you have an idea?


e.g. (s/def* string? [email1 email2 ... ]),