go ahead... be a heretic PerlMonks

### Re: Iterative vs Recursive Processes

 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.

Create A New User
Node Status?
node history
Node Type: note [id://257846]
help
Chatterbox?
 [marto]: both numerically and in terms of the problem :P marto ducks [Eily]: if there's a pun in there I didn't get it :x [marto]:
is there, but no content seemingly [Corion]: Hmm - these nodes are usually cached, so something doing the cache update broke, I guess [Eily]: I do see a content, the n°5 [marto]: 5 is an Odd_number [Corion]: That could fix itself within the next 24 hours :) [marto]: we should blame LanX [marto]: purely because he isn't here :P

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2018-03-20 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (248 votes). Check out past polls.

Notices?