On 2011-04-18, at 13:40, Louis-Philippe wrote:

> it seems like fib(50000) is not only too big for MRI ruby, but also =
Python
> and Lua and Rubinius panic on it...
There was some traffic on the Python mailing list maybe a year ago, it =
seems that Python will not implement TR optimization in the near (or =
likely far) future; Python's BDFL seems unconvinced of its value. AFAIK =
no TR PEP has ever been written. Lua's TR is very specific, I believe =
the recursive call  has to stand as a statement on its own. When I tried =
this with Lua 5.2.0 (alpha), I saw every evidence of TR optimization.

> function fib(n)
>>   local function fib1(n, a, b)
>>     if n =3D=3D 0 then
>>       return b
>>     else
>>       a, b =3D b, a + b
>>       return fib1(n - 1, a, b)=20
>>     end
>>   end
>>   return fib1(n, 0, 1)
>> end
> print(fib(1), fib(3), fib(10), fib(100), fib(1000), fib(10000))
1	3	89	5.7314784401382e+20	7.0330367711423e+208	=
inf
> print(fib(1000000))
inf

TR optimization can't easily be done on the JVM (and probably on .NET), =
because it interferes with the code verification process the JVM does. =
Accordingly, I doubt TR can be made mandatory for Ruby implementations, =
which is what I'd like. However, a boolean function or built-in constant =
that says whether it's performed would be very nice, so one can test =
this before running a program.=20

-- vincent=