On Fri, Nov 12, 1999 at 08:54:20PM +1100, Steve Bennett wrote:
> Ok, maybe 111,111! is asking a bit much...but would it be possible to
> write a factorial function that wouldn't stack overflow?  Like it would
> crash some other way...not enough memory, taking too long, etc etc?
> Stack overflow just seems a little ungraceful :)

The following tail-recursive factorial does not get a stack overflow
with me (Hugs 98 September 1999 on Debian GNU/Linux potato (i386)):

fac n = fac' 1 n
    where fac' rv n | n < 2     = rv
                    | otherwise = fac' (rv * n) (n-1)

-- 
%%% Antti-Juhani Kaijanaho % [EMAIL PROTECTED] % http://www.iki.fi/gaia/ %%%

                                  ""
                             (John Cage)

Reply via email to