gwtmp01 / mac.com schrieb:
> On Dec 18, 2005, at 9:57 AM, jwesley wrote:
> 
>> I found that ~1300 is the maximum depth of the stack on my machine....
>> So I can't use recursion to iterate over more than ~1300 items.
> 
> 
> I hope people do realize that they can change the
> maximum size of the stack allocated to their ruby process.  For
> example on Mac OS X using bash:
> 
> $ ulimit -s
> 8192
> $ ruby -e '@i = 0; def foo; @i += 1; foo; end; begin; foo; rescue;  puts 
> @i; end'
> 1204
> $ ulimit -s 16384
> $ ruby -e '@i = 0; def foo; @i += 1; foo; end; begin; foo; rescue;  puts 
> @i; end'
> 2484
> 
> 
> The ulimit command is built-in to the shell so if you are looking for
> ways to change the maximum size of the stack for your processes, look
> for ulimit or limit in your shell documentation.
> 
> I don't know enough about Windows to offer any hints for that  environment.

If you search in the tuby-talk archives, you can find this:

   @i = 0
   def foo
     @i += 1
     foo
   end

   begin
     foo
   rescue
     puts @i  # => 1342
   end

   self.class.tailcall_optimize :foo

   require "timeout"
   begin
     Timeout.timeout 10 do
       foo
     end
   rescue Exception => e
     puts @i  # => 542798
   end

Implemented in Ruby, so not as fast as real TRO.

Regards,
Pit