2.18 Exercise 2.18
To implement reverse, we will use an inner tail-recursive procedure that takes the accumulated reversed list and the unreversed portion of the original list as arguments.
(define (reverse l) (define (inner acc rest) (if (null? rest) acc (inner (cons (car rest) acc) (cdr rest)))) (inner '() l))