Are there problems that cannot be written using tail recursion?
Yes, actually you can take some code and convert every function call—and every return—into a tail call. What you end up with is called continuation-passing style, or CPS. For example, here’s a function containing two recursive calls: (define (count-tree t) (if (pair? t) (+ (count-tree (car t)) (count-tree (cdr t))) 1)) And here’s how it … Read more