;; rev-list-using-accum : (listof X) -> (listof X) ;; reverses a list ;; uses accumulator style (define (rev-list-using-accum l) {local ; accum is the reverse of all the elements of l ; just before l-tail [(define (rev-accum l-tail accum) (cond [(empty? l-tail) accum] [else (rev-accum (rest l-tail) (cons (first l-tail) accum))]))] (rev-accum l empty)}) ;; example/test (equal? (rev-list-using-accum (list 'a 1 5 'help 25)) (list 25 'help 5 1 'a)) #| For comparison, here's another version not using an accumulator but conforming to the standard structural recursion template for lists |# ;; rev-list : (listof X) -> (listof X) ;; reverses a list (define (rev-list l) (cond [(empty? l) empty] [else (append (rev-list (rest l)) (list (first l)))]))