This is a late reply to my own question but maybe it will be helpful to a 
future searcher.

http://blog.cognitect.com/blog/2016/10/5/interactive-development-with-clojurespec
has an example that showed me more clearly how to use :fn.

Specifically here's how I rewrote the spec:

(s/fdef mapper
        :args (s/cat :t :fake.flowrs-tests/positive-integer?
                     :b :fake.flowrs-tests/positive-integer?)
        :ret map?
        :fn (fn [{args :args ret :ret}]
              (= (:tacos ret)
                 (vec (range (:t args))))
              (= (:burritos ret)
                 (vec (range (:b args))))))

(s/exercise-fn `mapper) has the same behavior as before -- it exercises the 
*implementation* of the function.  But (stest/check `mapper) will return 
"Specification-based 
check failed" etc. when the implementation of mapper doesn't match.

As for the other part of the question: turning the logical test of :fn into 
a function that can be run to generate the result, that would require quite 
a bit of code rewriting.  A partial step is just to extract the :fn part of 
the code, and that can be done as follows:

(:fn (apply hash-map (rest (s/form (get (s/registry) 
'fake.flowrs/mapper)))))
;=>
(clojure.core/fn
 [{args :args, ret :ret}]
 (clojure.core/=
  (:tacos ret)
  (clojure.core/vec (clojure.core/range (:t args))))
 (clojure.core/=
  (:burritos ret)
  (clojure.core/vec (clojure.core/range (:b args)))))

The function so-obtained can be evaluated, but it won't "do" the job of the 
mapper function without further code transformation.  I'll leave it at that 
for now.

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