From: David Simas Date: 2007-04-17T03:58:28+09:00 Subject: Re: factorial in ruby On Tue, Apr 17, 2007 at 02:56:16AM +0900, Jason Roelofs wrote: > No and most likely not. > > def fact(n) > if n == 0 > 1 > else > n * fact(n-1) > end > end For large enough n, this will overflow the stack. Since Ruby doesn't optimize tail-recursive functions (and the above isn't tail recursive, anyway), you'd better write this function as a loop (left as an exercise). DGS > > Jason > > On 4/16/07, Trans wrote: > > > >Is factorial defined anywhere in Ruby's core or standard library. If > >not will it be in 1.9+? > > > >Thanks, > >T. > > > > > >