;;;;;;; Page 18 ;;;Exercise 1. It builds a list whose elements are each of the elements of the original list enclosed in parenthesis. (defun drop1 (u) (if (null u) nil (cons (list (car u)) (drop1 (cdr u))))) ;=> drop1 (drop1 '(a b c)) ;=> ((a) (b) (c)) ;;;Exercise 2. r2 constructs a list whose elements are the reversed lists of the original list. (defun r2 (u) (if (null u) nil (cons (reverse (car u)) (r2 (cdr u))))) ;=> r2 (r2 '((a b) (c d e) (e f g h))) ;=> ((b a) (e d c) (h g f e)) r3 constructs a list that is the mirror image of the original list, i.e. reverses the list and all its sublists. (defun r3 (u) (if (atom u) u (reverse (r4 u)))) ;=> r3 (defun r4 (u) (if (null u) nil (cons (r3 (car u)) (r4 (cdr u))))) ;=> r4 (r3 '(((a b)) (c (d e)) (e ((f g) h)))) ;=> (((h (g f)) e) ((e d) c) ((b a))) ;;;Exercise 3. r3' does the same thing as r3, but less efficently. In 3. there is a typing error. The parentheses around r3'[dx] should not be there. (defun r3-2 (u) (if (atom u) u (append (r3-2 (cdr u)) (list (r3-2 (car u)))))) ;=> r3-2 (r3-2 '(((a b)) (c (d e)) (e ((f g) h)))) ;=> (((h (g f)) e) ((e d) c) ((b a))) ;;;Exercise 4. r5 reverses a list. (defun r5 (u) (if (or (null u) (null (cdr u))) u (cons (car (r5 (cdr u))) (r5 (cons (car u) (r5 (cdr (r5 (cdr u))))))))) ;=> r5 (r5 '(a b c d)) ;=> (d c b a) (r5 '(((a b)) (c (d e)) (e ((f g) h)))) ;=> ((e ((f g) h)) (c (d e)) ((a b)))