On Fri, Feb 15, 2008 at 04:44:18PM -0800, Mark Schoonover wrote:
> Well, I thought I understood recursion until SICP.  I think I understand
> tail recursion too, and essentially it's converting a procedure where the
> last statement is calling itself into an iterative procedure instead of
> recursive.

Yes that is right.  The compiler does this for you.

> My problem is, I don't always see that in the code, but I know
> it's very important to Lisp. Any recursive procedure, more than likely will
> get written tail recursively.

What do you mean?  All you have to do is look at last expression right?

> Pretty much if you don't understand this, Lisp
> and SICP will be very difficult to understand.

And slow to run.  This is definitely a hurdle to learning functional languages.
No argument there.

> 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).

Can you post your code?  I'd be happy to look at it and try to help you.

> Maybe I'm not picturing this correctly in my head, and this could be the
> crux of my problem. Running it through the DrScheme debugger doesn't help
> much either as I watch the little green arrow bounce around like a pinball
> between parens. I guess Larry Wall knew what he was saying when he said lisp
> is like a bowlful of oatmeal with nail clippings in it - or something to
> that effect.

Yea....in C and other languages you know loops by the for and while keywords
and the braces.
It is obvious where they begin and end.  In Scheme they don't stand
out and announce themselves so clearly.  I don't what else to say to that
except to just agree with you.

> This is the other problem I'm having getting my brain around Lisp. It simply
> looks funny! Not funny haha, but funny weird. It almost looks obfuscated. I
> guess I'll get better at it the more I play with it, but for now it leaves
> me scratching my head and mumbling to myself.

It certainly is *different* than many languages we've probably all used before.
It seems weird to me too.  I'm still drawn to it for some reason.  Underneath
all that weirdness is an elegant austere simplicity.

Chris

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to