Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SICP

Name: Anonymous 2010-07-17 14:31

I'm having trouble visualizing the processed produced by the examples provided in exercise 1.9.

In case you've forgotten or are not familiar I've included the problem: http://pastebin.com/7PYmxrSS

Whenever I expand these recursive procedures I always end up getting an iterative process, so I don't believe I'm doing it correctly.
Any tips or tricks to help would be greatly appreciated.

Name: Anonymous 2010-07-17 14:47

I'm not sure why how you manage to get an iterative process for the first one, but if you are having trouble just draw it out and remember to evaluate your arguments before the applying the procedure
(define (+ a b)
  (if (= a 0)
  b
  (inc (+ (dec a) b))))
(+ 3 4)
(inc (+ (dec 3) 4))
(inc (+ 2 4))
(inc (inc (+ (dec 2) 4)))
(inc (inc (+ 1 4)))
(inc (inc (inc (+ (dec 1) 4))))
(inc (inc (inc (+ 0 4))))
(inc (inc (inc 4)))
(inc (inc 5))
(inc 6)
7

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List