2006/5/8, Elliot Temple <curi / curi.us>:
>
> On May 7, 2006, at 10:34 AM, Bob wrote:
>
> > Hi all,
> >
> > I am new to Ruby, and I have only known it through rails.  I was
> > wondering if it's a good idea to use recursion sparingly in Ruby?
> > How efficiently is it implemented?
>
> It's a good idea to recursion as much as you find convenient, and
> then test your code and see if it's too slow or not. If it's too
> slow, you have to figure out why, and you can put recursion on a long
> list of possible reasons.

I'm more on James' side: since recursion doesn't really scale in Ruby
I try to avoid it where possible from the start.

13:16:04 [~]: ruby -e 'def r(i)puts i;r i+1 end; r 0'|tail
-e:1:in `r': stack level too deep (SystemStackError)
        from -e:1:in `r'
        from -e:1
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
13:16:06 [~]:

Kind regards

robert

--
Have a look: http://www.flickr.com/photos/fussel-foto/