-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-db.lisp
More file actions
58 lines (45 loc) · 1.39 KB
/
Copy pathsimple-db.lisp
File metadata and controls
58 lines (45 loc) · 1.39 KB
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
53
54
55
56
57
58
(defvar *db* nil)
(defun make-eco (name company email telephone)
(list :name name :company company :email email :telephone telephone))
(defun add-record (eco) (push eco *db*))
(defun dump-db ()
(dolist( eco *db*)
(format t "~{~a:~10t~a~%~}~%" eco)))
(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)
(read-line *query-io*))
(defun prompt-for-eco ()
(make-eco
(prompt-read "Name")
(prompt-read "Company")
(prompt-read "Email")
(prompt-read "Telephone No")))
(defun add-ecologist ()
(loop (add-record (prompt-for-eco))
(if (not (y-or-n-p "Another? [y/n]: ")) (return))))
(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax
(print *db* out))))
(defun load-db (filename)
(with-open-file (in filename)
(with-standard-io-syntax
(setf *db* (read in)))))
(defun select-by-name (name)
(remove-if-not
#'(lambda (eco) (equal (getf eco :name) name))
*db*))
(defun select (selector-fn)
(remove-if-not
selector-fn
*db*))
(defun where (&key name company email telephone)
#'(lambda (eco)
(and
(if name (equal (getf eco :name) name) t)
(if company (equal (getf eco :company) company) t)
(if email (equal (getf eco :email) email) t)
(if telephone (equal (getf eco :telephone) telephone) t))))