I'm not sure how to turn count-forward into a tail recursive program. It takes a non-negative number, nand returns a list of integers from 0to n(including n).
Edit: Well, I finally got this to work. The problem was not that my current program was recursive, and I needed to make it tail recursive. It was simply wrong. The actual answer is really short and clean. Therefore, if someone else is stuck with this, and is also a complete noob programming, here are some tips that might help:
1) Your helper program is designed to keep track of the list so far.
2) Its basic case ... If x = 0, what are you doing? add 0 to .. something.
3) Repeat on x - 1 and then add x to your list so far.
4) When you get to your actual program, think-ahead, all you need is an assistant. But remember that this requires two arguments!
source
share