-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansiChapter1.lisp
executable file
·47 lines (43 loc) · 969 Bytes
/
ansiChapter1.lisp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;; solution to 3
(defun our-nth (lst position)
(if (= 0 position)
(car lst)
(if (cdr lst)
(our-nth (cdr lst) (- position 1))
nil)))
;; 4
(defun greater (a b)
(if (> a b)
a
b))
(defun a (a b)
((let ((x 1))
((if (test)
())))))
;; 5
(defun enigma (x)
(and (not (null x))
(or (null (car x))
(enigma (cdr x)))))
(defun mystery (x y)
(if (null y)
nil
(if (eql (car y) x)
0
(let ((z (mystery x (cdr y))))
(and z (+ z 1))))))
(defun main (&rest argv)
(declare (ignorable argv)))
`(1 2 '(3 5) 4 (3 1)) => '(1 2 5 5 5 4 1 1 1)
(defun uncompress (lst)
(if (null lst)
nil
(let ((element (car lst)))
(if (consp element)
(append (list-of (car element) (cdr element)) (uncompress (cdr lst)) )
(cons element (uncompress (cdr lst)))))))
(defun list-of (n el)
(if (zerop n)
nil
(cons el (list-of (- n 1) el))))
;;; vim: set ft=lisp lisp: