Does Ruby optimize tail-call recursion?

Hi,
I'm wondering if Ruby 1.9 optimizes tail-call recursion?
I've read some reports that say yes, and some that say no. Does anyone
know?

Thanks
  -Patrick

···

--
Posted via http://www.ruby-forum.com/.

Patrick Li wrote:

Hi,
I'm wondering if Ruby 1.9 optimizes tail-call recursion?
I've read some reports that say yes, and some that say no. Does anyone
know?

Thanks
  -Patrick

The 1.8.x versions do not.

···

--
Posted via http://www.ruby-forum.com/.

Patrick Li <patrickli_2001@hotmail.com> writes:

Hi,
I'm wondering if Ruby 1.9 optimizes tail-call recursion?
I've read some reports that say yes, and some that say no. Does anyone
know?

I just compiled the ruby svn trunk with all defaults:

./ruby -v
ruby 1.9.0 (2008-08-30 revision 18932) [i686-linux]

./ruby -e 'def bla(); bla(); end; bla()'
-e:1:in `bla': stack level too deep (SystemStackError)
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
         ... 7692 levels...
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `<main>'

So I guess the answer is: no, it does not optimize tail calls.

···

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

vm_opts.h:

#define OPT_TAILCALL_OPTIMIZATION 0

Set to 1, rebuild. The comments suggest it can be changed at runtime
via VM::CompileOption, which doesn't seem to exist. Hopefully it'll be
enabled by default at some point in future.

···

* Patrick Li (patrickli_2001@hotmail.com) wrote:

I'm wondering if Ruby 1.9 optimizes tail-call recursion? I've read
some reports that say yes, and some that say no. Does anyone know?

--
Thomas 'Freaky' Hurst
    http://hur.st/

Thank you for verifying. That's all I wanted to know.
  -Patrick

···

--
Posted via http://www.ruby-forum.com/.

Hi,

Thomas Hurst wrote:

vm_opts.h:

#define OPT_TAILCALL_OPTIMIZATION 0

Set to 1, rebuild. The comments suggest it can be changed at runtime
via VM::CompileOption, which doesn't seem to exist. Hopefully it'll be
enabled by default at some point in future.

In fact, I don't check this option. So some bugs may hide on this option. And backtrace (what you see on exception) is changed. It's convention issue.

···

--
// SASADA Koichi at atdot dot net

Joost Diepenmaat wrote:

./ruby -e 'def bla(); bla(); end; bla()'
-e:1:in `bla': stack level too deep (SystemStackError)
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
         ... 7692 levels...
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `bla'
        from -e:1:in `<main>'

On my machine:

ruby -e 'def bla(); bla(); end; bla()'
-e:1:in `bla': stack level too deep (SystemStackError)
        from -e:1:in `bla'
        from -e:1

I use Ruby version from windows one-click installer, 1.8.6.

···

--
Posted via http://www.ruby-forum.com/.