Fork me on GitHub
#clojure-spec
<
2017-05-11
>
rmuslimov07:05:19

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

rmuslimov07:05:29

ah, you’re right. Sorry for dumb question

slipset14:05:22

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

danielcompton22:05:41

You can also use Orchestra to instrument your spec return values: https://github.com/jeaye/orchestra/

rmuslimov20:05:52

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]))

xiongtx20:05:26

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

rmuslimov20:05:07

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.

john21:05:46

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

john21:05:21

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.

rmuslimov21:05:06

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

john21:05:54

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

john21:05:20

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

john21:05:44

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

john21:05:05

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

john21:05:33

(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

john21:05:51

macro away then 🙂

caio21:05:43

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

mobileink21:05:31

not that i know of. you have an idea?

mobileink21:05:41

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