P08: 連続して出現したエレメントを一つにまとめる。
(car nil) (cdr nil)がそれぞれnilを返すのを忘れててはまりました。
;;; ;; P08 (**) Eliminate consecutive duplicates of list elements ;; If a list contains repeated elements they should be replaced with a single ;; copy of the elemnt. The order of the elements should not be changed. ;; ;; Example: ;; * (compress '(a a a a b c c a a d e e e e)) ;; (a b c a d e) (defun compress (lis) (if (null lis) lis (let ((acc (list (car lis)))) (dolist (elem (cdr lis)) (when (not (eql (car acc) elem)) (push elem acc))) (reverse acc)))) (compress '(a a a a b c c a a d e e e e)) ;; => (A B C A D E) (compress '(nil nil nil nil nil t t t t t nil nil)) ;; => (NIL T NIL) (compress '(t t t t t nil nil nil nil nil t t)) ;;=> (T NIL T) (compress nil) ;;=> NIL