Deep reverse

Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements reversed and with all sublists deep-reversed as well. For example,

(define x (list (list 1 2) (list 3 4)))

x
((1 2) (3 4))

(reverse x)
((3 4) (1 2))

(deep-reverse x)
((4 3) (2 1))

    # Alikhan Askarov
    8 months ago
    не так сложно как кажется
Authentication required

You must log in to post a comment.

Login
(define x (list (list 1 2) (list 3 4)))
(define y '((1 2)(3 4)(5 6)))

(check-equal? (deep-reverse x) (list (list 4 3) (list 2 1)))
(check-equal? (deep-reverse y) '((6 5)(4 3)(2 1)))