From: "Wolfgang Nádasi-Donner" Date: 2009-03-08T22:34:14+09:00 Subject: [ruby-core:22739] Re: Ruby 1.9.1 and tail recursion optimization Wolfgang N�dasi-Donner schrieb: > Moin, moin! > > I was a little bit surprized that the following code snippets run into > stack overflow... > > myprompt> irb191-p0 > irb(main):001:0> def a > irb(main):002:1> b=2+1 > irb(main):003:1> a > irb(main):004:1> end > => nil > irb(main):005:0> a > > ...and... > > myprompt> irb191-p0 > irb(main):001:0> f = lambda{print "-";STDOUT.flush;f[]} > => # > irb(main):002:0> f[] > > ...because I thought Ruby 1.9.1 has tail recursion optimization > implemented. > > Was this a wrong assumption? I read one minute ago in German Ruby-Forum, that it isn't implemented in Ruby 1.9.1. One main reason was, that it is not possible under JVM. Tail recursion optimization is an implementation detail, a very important one for functional programming, but not a feature of the language itself. So why not ad a constant, maybe named TAILRECURSION, which will be set to true, if tail recursion optimization is supported as a feature of the implemntation? If one wants use Ruby 1.9.n as a vihicle for functional programming this optimization is an important thing. Wolfgang N�dasi-Donner