[plt-scheme] Fac calculus and memory swapping...
On Nov 6, 2006, at 4:53 AM, Guillaume R. wrote:
> Hello
> I'm quite a newbie in the functionnal world. So I decided to learn
> more on
> recursive algorithms using scheme.
> Here is my problem. I write this piece of code
>
> ;; should calculate n!
> (define (fac n)
> (if (= n 0)
> 1
> (* n (fac ( - n 1)))))
>
> For me this should work. Indeed it doesnt: if I try (fac 5) my
> computer is
> swapping using 92,5% of my memory (!). I tried this snippet on a
> freebsd
> computer with a DrScheme from 8september svn and on a linux box with a
> drscheme 350.
> Same results on both...So is it a memory leak or am I wrong in my
> definition
> of n! ?
Mac Powerbook G4 1Gb, stoneage (i.e. pre-Intell)
Welcome to DrScheme, version 352.9-svn31oct2006.
Language: Intermediate Student.
> (time (fac 5))
cpu time: 1 real time: 1 gc time: 0
120