чекнул пару ссылок, так?
(def step 0.5)
(defn calculate-trap-area [a b h]
(* h (/ (+ a b) 2)))
(def m-calc-positive-integral
(memoize
(fn [f x]
(let [a (- x step)
b x
calculate-area (calculate-trap-area (f b) (f a) step)]
(if (neg? a)
0
(+ calculate-area (m-calc-positive-integral f a)))))))
(defn integral [func]
(fn [x]
(let [modifier (if (neg? x) -1 1)]
(*
modifier
(m-calc-positive-integral func (* x modifier))))))
(def heavy-func (fn [x] (do (println (str "calculate f(" x ")")) (Thread/sleep 100) (* x x))))
(defn -main [& args]
(println (time ((integral heavy-func) 5)))
(println (time ((integral heavy-func) -5)))
(testing "Integral"
(testing "with positive numbers"
(is (= 41.875 ((integral #(* % %)) 5))))
(testing "with negative numbers"
(is (= -41.875 ((integral #(* % %)) -5))))))