Fork me on GitHub
#clojure-spec
<
2017-05-23
>
danielcompton04:05:18

What is the right way to spec functions that can throw exceptions? It seems like I need to allow :ret to be nil to handle exceptions here

Alex Miller (Clojure team)16:05:51

If there is an exception there is no return value

Alex Miller (Clojure team)16:05:14

Exceptions are not covered by spec

Alex Miller (Clojure team)16:05:36

Because they are ... exceptional cases

deplect17:05:26

hai all, how do we handle ordering with spec?

Alex Miller (Clojure team)17:05:44

you’ll need to explain more, not sure what you mean

caio18:05:31

(s/and sorted? ...)?

caio18:05:28

(not the clojure.core/sorted?)

andrewmcveigh18:05:44

Is this expected?

(let [n 2
      t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count n) [1 2]))
=> [1 2]

(let [n nil
      t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count n) [1 2]))
=> :clojure.spec.alpha/invalid

(let [t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count nil) [1 2]))
=> [1 2]

andrewmcveigh18:05:24

I just wonder if this is a bug, or if the s/every macro is meant to check the 'n symbol rather than what it evals to.

Alex Miller (Clojure team)19:05:03

I think I’d call it a bug, given the docstring states that nil is the default which seems to imply you could pass it

Alex Miller (Clojure team)19:05:07

feel free to file a jira

andrewmcveigh19:05:49

Ok, will do. Thanks