From: Brian Candler Date: 2008-09-15T16:26:57+09:00 Subject: Re: I thought ruby didn't optimize tailcalls? cnb wrote: > Im using ruby 1.8.6 mri. and it seems to optimize tailcalls which I > have been told it doesn't. what else could be going on here? With that program, factail(2000) works for me but factail(5000) bombs out with "stack too deep". So I guess you just have a larger default stack size than me. Factorials generate very large Bignums which will slow things down substantially for large numbers. I suggest you try something simpler: def counttail(n, acc=0) if n > 0 then counttail(n-1, acc+1) else acc end end Then you can try counttail(10_000), counttail(100_000), counttail(1_000_000) etc until you can show your stack overflowing. If counttail(10_000_000) still works, then post your exact version of MRI and where you got it from. Perhaps you have some sort of patched version (although I've not come across such a patch myself) Regards, Brian. -- Posted via http://www.ruby-forum.com/.