Author Topic: tail recursion  (Read 876 times)

0 Members and 1 Guest are viewing this topic.

Offline Polpolion

  • The sizzle, it thinks!
  • 211
    • Minecraft
seriously **** that ****

why would even want to bother

it's really hard to implement in most cases even if you understand non-tail recursion, and it's STILL WORSE THAN NORMAL ITERATION

don't even care that it might prevent offbyone errors; in the time it takes to implement a tail recursive function, you could probably write the function iteratively and check it over for offbyone errors

seriously, what gives

 

Offline Iss Mneur

  • 210
  • TODO:
The nice thing about tail recursion is, if you have a compiler that is optimizing it will transform the code into a non recursive iterative call. Which means that you get the advantages of readability that you get with recursion and without the overhead of recursion.
"I love deadlines. I like the whooshing sound they make as they fly by." -Douglas Adams
wxLauncher 0.9.4 public beta (now with no config file editing for FRED) | wxLauncher 2.0 Request for Comments

 

Offline Flipside

  • əp!sd!l£
  • 212
Used to use this a lot in Z80 because of limited CPU speed and stack-size, a jmp used less cycles than a jsr, so with iterative calls the savings used to be quite noticeable, and you didn't kill the stack.

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
I don't know about tail recursion specifically, but I do know that I found working with Scheme to be utter hell in the one class I took which used it, as the whole damn language is recursive.  Ugh.

 

Offline Qent

  • 29
Really? :( They told us up front, "If you can get recursion, you'll be fine; if not, you're screwed," and soon I grew to love it.