From: Gavin Sinclair Date: 2003-08-07T17:38:21+09:00 Subject: Re: Ruby Query > > schrieb im Newsbeitrag > news:221d8dbe.0308062037.2a5558f2@posting.google.com... >> Ruby is a nice and expressive language. Now my favourite Ruby site is >> http://whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh >> >> I have a query about Ruby >> 1) Like Python can I increase the maximum depth of Ruby Interpreter >> Stack? This will help to calculate factorial(1000) recursively. >> Without increasing the recursion limit, it will not possible to >> calculate factorial(1000) recursively with Ruby 1.8 (Win 98). It is >> possible to do the same with Python. > > Hmmm... Calculating factorial recursively is really inefficient and > after all, Ruby is not a functional language although it has some > features of them > > def fact1(n) > n == 1 ? 1 : n*fact1(n-1) > end I am out of my depth here, but calculating factorial recursively is not intrinsically inefficient, as it can be defined in a tail-recursive manner (unlike fibonacci). It's Ruby that's inefficient by not "supporting" tail-recursion optimisation, not the algorithm itself. That said, your benchmarks (snipped) show a speed difference of only a factor of two between iterative and recursive, which surprised me. Further proof that Ruby does not truly have POLS! Gavin post.puts ""