Monday 15 February 2010

recursion - SICP recursive process vs iterative process: using a recursive procedure to generate an iterative process -


By giving an example of such a code given below in SIC, the author explains how to solve a factual problem To use the process: Define (fact1) (fact 1) 1 (n) (define (actual object product counter counter-count) (if (& gt; counter max- Counting product (fact-maker (counter product) (+ counter 1) maximum-count)))

And say that "It may seem disturbing that we refer to a recursive process like creating a reality, it is a repetition process. However, this process actually moves: its position is completely captured by its three state variables. , And an interpreter needs to keep track of only three variables in order to execute this process. "

I do not understand What does it mean Ekk. What is the difference between recursive process and a recursive process? And why did he repeat the recurrent process after making the repetition process?

A recursive process needs to maintain the position of the caller, For example, if the recursive call is in progress, if you have written:

  (define (fact-recurs, en) (if (& lt; n 2) 1 (* n (fact- Remember the external call to  n  and wait for multiplying the inner call before multiplying it.             P>   Em>, the first state can be abandoned. This example code is possible because all the necessary information has been passed as a parameter in the recursive call. Variables are not required in an external call, so nothing should be kept on the stack.  

Since the parameters of the external call are no longer required, the recurring call can be translated into the assignment again:

  (set! Product (* counter product)   

and then just jumps at the beginning of the process. (Set!

No comments:

Post a Comment