Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Iterative vs Recursive Processes

by vladb (Vicar)
on May 13, 2003 at 17:47 UTC ( #257846=note: print w/replies, xml ) Need Help??

in reply to Iterative vs Recursive Processes

I may be missing some deeper nested (no pun intended :) point, but how is your factorial_iterative() interative? Inside you simply make a call to fi_helper() which is a recursive subroutine.

An interative routine would be the one which didn't make a call to itself and instead used loops to complete the task (as some of other commenters already did).

(ps: the subject of this thread is great and I enjoyed reading both your and other monks' posts :)

update: mvaline, ahh that makes sense now ;-) Thanks for your reply.

"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce
the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true."

Robert Wilensky, University of California

Replies are listed 'Best First'.
Re: Re: Iterative vs Recursive Processes
by mvaline (Friar) on May 15, 2003 at 16:14 UTC

    It is a bit tricky. The point I made in my post is that there is (or at least should) a difference between a recursive procedure and a recursive process. The term recursive procedure only refers to the fact that the procedure definition refers to itself. This doesn't necessarily result in a recursive process.

    The difference between the processes is whether the process is characterized by linear growth because of delayed stack operations (recursive) or whether the process is static because the state of the program is defined entirely by state variables.

    fi_helper() is indeed a recursive procedure, but written in a language that supports tail-recursion (like LISP), it doesn't generate a recursive process. My question was whether it would generate a recursive process in Perl.

      I see - you refer to the source as describing the procedure. So in this case a given procedure can within its definition use itself and thus become a recursive procedure. Moving onto "process", you're referring to the state accrued through execution of a process. You're stating that a process is recursive if it maintains its stack (sort of). You can have perl throw away the current context by using the goto &sub function though that isn't an optimal way to code. You're more likely to write that code as an interator if you intend to write it in a way that perl won't penalize you for.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://257846]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-01-21 00:42 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (180 votes). Check out past polls.