[Tutor] recursive function example

spir denis.spir at gmail.com
Wed Dec 11 22:08:46 CET 2013


On 12/11/2013 07:15 PM, Alan Gauld wrote:
> Remember we are calling mul() several times, each with a new set of values.
>
> So mul(3,2) calls mul(3,1)
> and mul(3,1) calls mul(3,0)
>
> mul(3.0) returns 0 to mul(3,1)
> mul(3,1) then returns 3+0 => 3 to mul(3,2)
> mul(3,2) returns 3+3 => 6.


This is a very clear explanation of the process: especially that the sequence of 
calls goes top->down, while the sequence of execution goes backward, down->up. 
(And the latter is what counts in forming the result. If we were recording 
partial results [sub_res in my examples], then they would be backwards)

denis


More information about the Tutor mailing list