What is the function to a list in Scheme? It needs to be able to handle nested lists.
So that if you do something like (reverse \'(a (b c d) e))
you\'ll
This is one way that you can make a reverse function that applies to nested lists:
(define (reverse-deep l)
(map (lambda (x) (if (list? x) (reverse-deep x) x)) (reverse l)))
Explanation in pseudo-code:
Start by reversing the list as you would normally do
Then for each element in the reversed list:
- If the element is a list itself: Apply the procedure recursively
- Else: Don't touch the element