Where can I place the print function inside a loop/recur in Clojure?

Viewed 602

Getting started with Clojure and functional programming. Looking at the slow example of adding numbers in a range from the not-yet-published programming Clojure book third edition, chapter 10.

How to add a println to this loop so that I can see the values of sum as they change?

; performance demo only, don't write code like this 
(defn sum-to [n]
  (loop [i 1 sum 0]
    (if (<= i n)
      (recur (inc i) (+ i sum))
      sum)))
4 Answers
Related