-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter-2.lisp
52 lines (44 loc) · 896 Bytes
/
chapter-2.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
48
49
50
51
52
;; 7)
(defun my-nest-listp (x)
(if (null x)
nil
(or
(listp (car x))
(my-nest-listp (cdr x)))))
;; 8-a)
(defun print-dot (n)
(do
((i 1 (+ i 1)))
((> i n) (format t "~%"))
(format t ".")))
(defun print-dot-r (n)
(if (eql n 0)
(format t "~%")
(progn
(format t ".")
(print-dot-r (- n 1)))))
;; 8-b)
(defun count-element (v lst)
(let ((c 0))
(dolist (i lst)
(if (eql i v)
(setf c (+ c 1))))
c))
(defun count-element-r (v lst)
(if (null lst)
0
(if (not (eql v (car lst)))
(count-element-r v (cdr lst))
(+ 1 (count-element-r v (cdr lst))))))
;; 9-a)
(defun sum-ignore-nil-use-remove (lst)
(apply #'+ (remove nil lst))
)
;; 9-b)
(defun sum-ignore-nil (lst)
(if (null lst)
0
(let ((x (car lst)))
(if (null x)
(sum-ignore-nil (cdr lst))
(+ x (sum-ignore-nil (cdr lst)))))))