Clojure-Intro-Course / clojure-intro-class

NOTE: This repository is obsolete. Was: A pilot project to use Clojure for introductory computer science courses at the University of Minnesota - Morris
20 stars 3 forks source link

multi-arg functions different spec conditions #116

Closed elenam closed 8 years ago

elenam commented 8 years ago

The current spec

(s/fdef reduce
        :args (s/cat :check-funtion ifn? :dummy (s/? ::s/any) :check-seqable seqable?))

gives an arity error, not a type error on (reduce + :not-a-collection):

Error: You cannot pass two arguments to a function reduce, need two or three,
in the function call (reduce + :not-a-collection)

This is because when the condition for the second argument fails, it expects a third argument that would've made spec pass.

repeat and repeatedly have the same issue.

real-mj-song commented 8 years ago

(reduce 1 [1 2 3]); ; - :two-case fails at ifn? ; - :three-case fails at length3? (reduce 1) ; - :two-case fails at length2? ; - :three-case fails at length3? (reduce 1 2 3 3) ; - :two-case fails at length2? ; - :three-case fails at length3? (reduce + 0 [] 1) ; - :two-case fails at length2? ; - :three-case fails at length3? (reduce 1 2 3) ; - :two-case fails at length2? ; - :three-case fails at ifn? (reduce + 3) ; - :two-case fails at seqable? ; - :three-case fails at length3? (reduce + 2 2) ; - :two-case fails at length2? ; - :three-case fails at seqable?