Добавил:
wolfain@mail.ru Хз кто это читает, но знайте - открыт к любым новым знакомствам (нет). Хех. Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

3

.txt
Скачиваний:
10
Добавлен:
04.03.2018
Размер:
2 Кб
Скачать
(setf *database* ())

(defun add-record (&key d n pt)
(setf *database* (cons (list :destination d :id n :plan-type pt) *database*)))

(defun printAll (&optional (outstr NIL))
setf *database* ())

(defun printAll (&optional (outstr NIL))
(dolist (item *database*)
(print item outstr)))

(defun dest-selector (dest-value) #’(lambda (x) (equal (getf x :destination) dest-value)))
(defun id-selector (id-value) #’(lambda (x) (equal (getf x :id) id-value)))
(defun ptype-selector (ptype-value) #’(lambda (x) (equal (getf x :plan-type) ptype-value)))


(defun select-by-plan-type ()
(setq res (remove-if-not (ptype-selector (read)) *database*))
(if (equal res nil) "no matches" res))

(defun update (selector-func &key d n pt)
(setf *database*
(mapcar #'(lambda (record)
(when (funcall selector-func record)
(if d (setf (getf record :desination) d))
(if n (setf (getf record :id) n))
(if pt (setf (getf record :plan-type) pt)))
record)
*database*)))

(defun save-to-file ()
(setf out (open "E:\\extern.txt" :direction :output))
(printAll out)
(close out))

(defun load-from-file ()
(setf in (open "E:\\extern.txt" :direction :input))
(loop
(setf item (read in nil 'eof))
(if (equal item 'eof) (return *database*))
(setf *database* (cons item *database*)))
(close in) *database*)

(add-record :d "five" :n 5 :pt "fivetype")
(add-record :d "seven" :n 7 :pt "seventype")
(add-record :d "six" :n 6 :pt "sixtype")
(add-record :d "nine" :n 9 :pt "ninetype")
(select-by-plan-type) "sixtype"
(select-by-plan-type) "new"
(update (ptype-selector "fivetype") :d "New Dest" :n 55)
(printAll)
Соседние файлы в предмете Искусственный интеллект