- Feb 3, 2005
- 7,326
- 2
- 76
I'm not quite sure I understand tail-recursion (especially when it comes to actually doing it/applying it to specific problems). I mostly understand it if I watch someone do it (while explaining), but when it comes to doing it on my own, I either don't know what to do or get stuck.
Here's a specific problem:
Define a procedure count-forwards that takes a nonnegative integer n and returns a list of integers from 0 up to and including n. Hint: define and call a tail-recursive helper procedure.
> (count-forwards 0)
(0)
> (count-forwards 5)
(0 1 2 3 4 5)
I actually think I just figured out what I may need to do (as I typed this), but in the event I still don't, I'd like to have this posted. I appreciate any help anyone can give.
Here's a specific problem:
Define a procedure count-forwards that takes a nonnegative integer n and returns a list of integers from 0 up to and including n. Hint: define and call a tail-recursive helper procedure.
> (count-forwards 0)
(0)
> (count-forwards 5)
(0 1 2 3 4 5)
I actually think I just figured out what I may need to do (as I typed this), but in the event I still don't, I'd like to have this posted. I appreciate any help anyone can give.
