He gives a scheme recursive program to add 2 numbers, any insight would be appreciated!

Scheme version:

- Code: Select all
`(DEFINE (+ X Y)`

(IF (= X 0)

Y

(1+ (+ (-1+ X) Y))))

(I've translated to Clojure and added some print statements).

- Code: Select all
`(defn z [x y]`

(if (= x 0)

(do (println "x is zero x: " x " y: " y)

y)

(do (println "else x: " x " y: " y)

(inc (z (dec x) y)))))

here is the output:

- Code: Select all
`user> (z 4 9)`

else x: 4 y: 9

else x: 3 y: 9

else x: 2 y: 9

else x: 1 y: 9

x is zero x: 0 y: 9

13

This I do not understand: the code says (= x 0) then y. When x is 0 y is 9 not 13!