[Tutor] parsing--is this right?
Paul Tremblay
phthenry@earthlink.net
Tue, 11 Jun 2002 22:38:14 -0400
On Tue, Jun 11, 2002 at 02:06:57PM -0700, Danny Yoo wrote:
Thanks Derrick and Danny.
Recursion is both intuitive and counter-intuitive. For example,
Derrick showed a fairly simple example using a factorial. But what
happens to the return in this line?
return n * fact( n-1 )
You think of return as getting one value, but the return somehow
has to wait and build up a value. Also, how come the function
doesn't return 1? The first part of the function says that it
should return 1 if n is equal to one. At some point, n becomes 1.
So why don't we see 1, and why doesn't the function stop?
On the other hand, recusion is intuititve in a way that is just
beyond my reach. I say this because I have written so much
duplicate code, and I'm always thinking, "How can I re-use this
code?" Of course, not all of this code is an example of
recursion, but I bet if I went back and looked, some of the
problems would be.
Anyway, all this should give me a bit to think about for a while.
Paul
--
************************
*Paul Tremblay *
*phthenry@earthlink.net*
************************