3 Write another version of reverse that reverses not only th

3. Write another version of reverse that reverses not only the top level elements, but also recursively reverses the elements of all sub-lists. e.g. (reverse \'((1 2) 3 4 (5 6 7)) ) returns ((7 6 5) 4 3 (2 1))

Solution

(defun reverse (L)

(cond

( (null? L) nil )

( (listp (car L) )

(append

(reverse (cdr L) )

(list (reverse (car L) ) ) ) )

( t

( append

( reverse (cdr L) )

(list ( car L) ) ) ) ) )

( reverse \'((1 2) 3 4 (5 6 7) )

3. Write another version of reverse that reverses not only the top level elements, but also recursively reverses the elements of all sub-lists. e.g. (reverse \'

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site