Solution to the 99 LISP Problems #11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| (defun pack-first (alist)
(if (null alist)
nil
(if (equalp
(car alist)
(cadr alist))
(append (list (car alist)) (pack-first (cdr alist)))
(list (car alist)))))
(defun trim-first (alist)
(if (null alist)
nil
(if (not (equalp
(car alist)
(cadr alist)))
(cdr alist)
(trim-first (cdr alist)))))
(defun encode-modified (alist)
(if (null alist)
nil
(append
(if (= (length (pack-first alist)) 1)
(list (car alist))
(list (list (length (pack-first alist)) (car alist))))
(encode-modified (trim-first alist)))))
|
Lisp dialect: Steel Bank Common Lisp