[CCONTRACTS-4] provide macro fails for multiple constraints Created: 28/Jan/14 Updated: 28/Jan/14
The following code shows 2 ways for defining a function with constraints.
=> it works as expected using the with-constraints macro
(require '[clojure.core.contracts :as ccc])
;; because the provide macro alters the var-root, let's keep two separate identical functions for the test.
(defn qux [x] x)
;; define 2 contracts
(def c2 (ccc/contract c2-cx "should have one digit"
;; using the provide macro => c1 is asserted, c2 never. When we swap around c2 c1, then c2 is asserted, c1 never
;; on the other hand, using with-constraints works as expected.
(qux 2) ;; expected assertion "should be odd"
(qux-g 2) ;; should be odd