Given that we now have to use clojure.spec.test to get :ret / :fn tested, we 
lose the “nice” exceptions explaining the conformance failure:

 

Alpha 5:

 

;;=> ExceptionInfo Call to #'spec-example.core/ranged-rand did not conform to 
spec:

;;=> At: [:fn] val: {:args {:start 8, :end 10}, :ret 7} fails predicate: (>= 
(:ret %) (-> % :args :start))

;;=> :clojure.spec/args  (8 10)

;;=>   clojure.core/ex-info (core.clj:4617)

 

Alpha 6:

 

boot.user=> (t/check-var #'ranged-rand)

{:result {:clojure.spec/problems {[] {:pred (>= (:ret %) (-> % :args :start)), 
:val {:args {:start -1, :end 2}, :ret -2}, :via [], :in []}}, :failed-on :fn}, 
:seed 1466016600676, :failing-size 4, :num-tests 5, :fail [(-1 2)], :shrunk 
{:total-nodes-visited 5, :depth 1, :result {:clojure.spec/problems {[] {:pred 
(>= (:ret %) (-> % :args :start)), :val {:args {:start -1, :end 1}, :ret -2}, 
:via [], :in []}}, :failed-on :fn}, :smallest [(-1 1)]}}

 

Are there plans to provide an “explain” equivalent for this?

 

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


 

On 6/15/16, 11:33 AM, "Alex Miller" <clojure@googlegroups.com on behalf of 
a...@puredanger.com> wrote:

 

I'm in the process of updating that part of the guide right now, should be done 
by end of day.

On Wednesday, June 15, 2016 at 12:30:55 PM UTC-5, webber wrote:

Maybe, the following is the same reason.

 

```
(defn ranged-rand   ;; BROKEN!

  "Returns random integer in range start <= rand < end"

  [start end]

  (+ start (rand-int (- start end))))

 

(s/fdef ranged-rand

  :args (s/and (s/cat :start integer? :end integer?)

               #(< (:start %) (:end %)))

  :ret integer?

  :fn (s/and #(>= (:ret %) (-> % :args :start))

             #(< (:ret %) (-> % :args :end))))

(ranged-rand 8 10)

;;=> ExceptionInfo Call to #'spec-example.core/ranged-rand did not conform to 
spec:

;;=> At: [:fn] val: {:args {:start 8, :end 10}, :ret 7} fails predicate: (>= 
(:ret %) (-> % :args :start))

;;=> :clojure.spec/args  (8 10)

;;=>   clojure.core/ex-info (core.clj:4617)

(println *clojure-version*)

;;=> {:major 1, :minor 9, :incremental 0, :qualifier alpha1}

 

(s/instrument #'ranged-rand)

(ranged-rand 8 10)

;;=> 7

(println *clojure-version*)

;;=> {:major 1, :minor 9, :incremental 0, :qualifier alpha6}

```

 

user=> (require '[clojure.spec :as s])
user=> (defn dummy [x] (if x "yes" "no"))
user=> (s/fdef dummy
  #_=>   :args (s/cat :x integer?)
  #_=>   :ret  integer?)
user=> (s/instrument #'dummy)
user=> (dummy 3) (println *clojure-version*)
ExceptionInfo Call to #'user/dummy did not conform to spec:
val: "yes" fails at: [:ret] predicate: integer?
:clojure.spec/args  (3)
  clojure.core/ex-info (core.clj:4703)
{:major 1, :minor 9, :incremental 0, :qualifier alpha5}

;-------------------------------------------------------------------

user=> (dummy 3) (println *clojure-version*)
"yes"
{:major 1, :minor 9, :incremental 0, :qualifier alpha6}

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to