Reading through SICP Distilled and trying to wrap my head around iterative vs recursive processes. The example given is:
(defn + [a b]
(if (= a 0) b (inc (+ (dec a) b))))
(defn + [a b]
(if (= a 0) b (+ (dec a) (inc b))))
Which of these is an iterative process (state is maintained entirely by the parameters to an iterative function) and which is a recursive process (state must be preserved "behind-the-scenes" while waiting for the previous function calls to finish.
My guess here is that the second is iterative because the arguments can be evaluated before the arguments are applied to the function, whereas the former will have to keep successive function calls on the stack waiting for the last +
operation to finish before it can unwind the stack, running inc
at each step.