(defun singletonp (the-list) (cond ((null the-list) nil) ((null (cdr the-list)) T) (T nil) ) ) Demo: Break 2 [7]> (singletonp '(a)) T Break 2 [7]> (singletonp '(1 2)) NIL Break 2 [7]> (singletonp '(a b c 2 3 4 1)) NIL (defun rac (the-list) (cond ((singletonp the-list) (car the-list) ) (T (rac(cdr the-list)) ) ) ) Demo: Break 2 [7]> (rac '(1)) 1. Trace: (RAC '(1)) 1. Trace: RAC ==> 1 1 Break 2 [7]> (rac '(1 2 3 4)) 1. Trace: (RAC '(1 2 3 4)) 2. Trace: (RAC '(2 3 4)) 3. Trace: (RAC '(3 4)) 4. Trace: (RAC '(4)) 4. Trace: RAC ==> 4 3. Trace: RAC ==> 4 2. Trace: RAC ==> 4 1. Trace: RAC ==> 4 4 (defun rdc (the-list) (cond ((singletonp the-list) nil ) (T (cons (car the-list) (rdc (cdr the-list))) ) ) ) Demo: [11]> (rdc '(1)) 1. Trace: (RDC '(1)) 1. Trace: RDC ==> NIL NIL [12]> (rdc '(1 2 3 4 5)) 1. Trace: (RDC '(1 2 3 4 5)) 2. Trace: (RDC '(2 3 4 5)) 3. Trace: (RDC '(3 4 5)) 4. Trace: (RDC '(4 5)) 5. Trace: (RDC '(5)) 5. Trace: RDC ==> NIL 4. Trace: RDC ==> (4) 3. Trace: RDC ==> (3 4) 2. Trace: RDC ==> (2 3 4) 1. Trace: RDC ==> (1 2 3 4) (1 2 3 4) (defun snoc (x the-list) (cond ((null the-list) (list x) ) (T (cons (car the-list) (snoc x (cdr the-list))) ) ) ) Demo: [25]> (snoc 'blue ()) 1. Trace: (SNOC 'BLUE 'NIL) 1. Trace: SNOC ==> (BLUE) (BLUE) [26]> (snoc 'blue '(red)) 1. Trace: (SNOC 'BLUE '(RED)) 2. Trace: (SNOC 'BLUE 'NIL) 2. Trace: SNOC ==> (BLUE) 1. Trace: SNOC ==> (RED BLUE) (RED BLUE) [27]> (snoc 'blue '(dark-blue light-blue sky-blue purple)) 1. Trace: (SNOC 'BLUE '(DARK-BLUE LIGHT-BLUE SKY-BLUE PURPLE)) 2. Trace: (SNOC 'BLUE '(LIGHT-BLUE SKY-BLUE PURPLE)) 3. Trace: (SNOC 'BLUE '(SKY-BLUE PURPLE)) 4. Trace: (SNOC 'BLUE '(PURPLE)) 5. Trace: (SNOC 'BLUE 'NIL) 5. Trace: SNOC ==> (BLUE) 4. Trace: SNOC ==> (PURPLE BLUE) 3. Trace: SNOC ==> (SKY-BLUE PURPLE BLUE) 2. Trace: SNOC ==> (LIGHT-BLUE SKY-BLUE PURPLE BLUE) 1. Trace: SNOC ==> (DARK-BLUE LIGHT-BLUE SKY-BLUE PURPLE BLUE) (DARK-BLUE LIGHT-BLUE SKY-BLUE PURPLE BLUE) (defun palindromep (the-list) (cond ((null the-list) T ) ((singletonp the-list) T ) ((eq (car the-list) (rac the-list)) (palindromep (cdr (rdc the-list))) ) ) ) Demo: [29]> (palindromep ()) 1. Trace: (PALINDROMEP 'NIL) 1. Trace: PALINDROMEP ==> T T Break 1 [31]> (palindromep '(palindrome)) 1. Trace: (PALINDROMEP '(PALINDROME)) 1. Trace: PALINDROMEP ==> T T Break 1 [31]> (palindromep '(clos sloc)) 1. Trace: (PALINDROMEP '(CLOS SLOC)) 1. Trace: PALINDROMEP ==> NIL NIL Break 1 [31]> (palindromep '(food drink food)) 1. Trace: (PALINDROMEP '(FOOD DRINK FOOD)) 2. Trace: (PALINDROMEP '(DRINK)) 2. Trace: PALINDROMEP ==> T 1. Trace: PALINDROMEP ==> T T Break 1 [31]> (palindromep '(1 2 3 4 5 4 3 2 1)) 1. Trace: (PALINDROMEP '(1 2 3 4 5 4 3 2 1)) 2. Trace: (PALINDROMEP '(2 3 4 5 4 3 2)) 3. Trace: (PALINDROMEP '(3 4 5 4 3)) 4. Trace: (PALINDROMEP '(4 5 4)) 5. Trace: (PALINDROMEP '(5)) 5. Trace: PALINDROMEP ==> T 4. Trace: PALINDROMEP ==> T 3. Trace: PALINDROMEP ==> T 2. Trace: PALINDROMEP ==> T 1. Trace: PALINDROMEP ==> T T Break 1 [31]> (palindromep '(hey hey my my my my hey hey)) 1. Trace: (PALINDROMEP '(HEY HEY MY MY MY MY HEY HEY)) 2. Trace: (PALINDROMEP '(HEY MY MY MY MY HEY)) 3. Trace: (PALINDROMEP '(MY MY MY MY)) 4. Trace: (PALINDROMEP '(MY MY)) 5. Trace: (PALINDROMEP 'NIL) 5. Trace: PALINDROMEP ==> T 4. Trace: PALINDROMEP ==> T 3. Trace: PALINDROMEP ==> T 2. Trace: PALINDROMEP ==> T 1. Trace: PALINDROMEP ==> T T