On Fri, Feb 15, 2008 at 11:18:34PM -0500, Mark Schoonover wrote: > Sure, but the code that's listed in the Tree Recursion section, it looks to > me the last expression is never reached.
Which one exactly? The Fibonacci sequence on p37? It will reach last expression for n > 1. > > > Ok, for example take a look at 1.2.2 Tree Recursion. I've entered the > > > recursive procedure for (fib n). I run it with (fib 5), but my output is > > > just 5. (I'm using DrScheme) I'm not sure where the 5 even comes from. > > > Actually, this particular example is more complicated than it initially > > > looks because there's double recursion going on. In the (else (+ (fib (- > > n > > > 1)) (fib (- n 2)))) portion, it looks to me the (- n 2) would never be > > > reached because (fib (- n 1)) is always called first, and it'll bail out > > > once (= n 1). See my other post where I write out (fib x) for few values of x. In the fib function the last expression in the cond is an ADDITION of fib function calls. They will BOTH be calculated. Clear now? Chris -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
