I am getting an error and do not know how to fix it. I have to calculate square root with approximation and it should stop on the 20th element.
Code:
(defn msqrt [n]
(aprox (n 1.0 1)))
(defn aprox [n prox part]
(if (= part 20)
prox
(+ (/ n (* 2 (aprox n part (+ part 1)))) (/ (aprox n prox (+ part 1))2)))
)
(msqrt 9)
In Clojure, the order you declare functions in matters. They don't get hoisted up like in Javascript. You can fix this by either:
defn aprox
above defn msqrt
declare aprox
to the top of your file to make it available