this post was submitted on 08 May 2025
9 points (100.0% liked)

Ruby

609 readers
9 users here now

A community for discussion and news about Ruby programming.

Learning Ruby?

Tools

Documentation

Books

Screencasts

News and updates

founded 2 years ago
MODERATORS
 

I wasn't able to find any up-to-date information about tail call optimization support in Ruby, so I decided to post this hoping that it will pop up next time someone might also be searching for this topic...

What I was able to figure out is that TCO can be enabled in Ruby 3.4 via a compile option like so:

RubyVM::InstructionSequence.compile_option = {tailcall_optimization: true}

def tailSumUntil(n, m)
  n == 0 ? m : tailSumUntil(n - 1, n + m)
end

tailSumUntil(100_000_000, 0)
# => 5000000050000000
no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here