函数

;; an ordinary recursive call: the stack is not endless,
;; a deep recursion overflows it
(defn fibonacci [x]
  (if (< x 2)
    x
    (+ (fibonacci (- x 1)) (fibonacci (- x 2)))))

(println "f10 is" (fibonacci 10))
;; f10 is 55

;; recur is a tail call: it reuses the same frame, so the depth is unlimited
(defn sum-to [n]
  (loop [i n acc 0]
    (if (zero? i)
      acc
      (recur (dec i) (+ acc i)))))

(println "sum to 100000 is" (sum-to 100000))