home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
aijournl
/
1986_10
/
inside3.ltg
< prev
next >
Wrap
Text File
|
1986-07-16
|
1KB
|
44 lines
LISTING 3
;;; Production System. Copyright Raul E. Valdes-Perez, 1986. All Rights Reserved.
;;; USER FUNCTIONS ARE:
;;; (defrule name lhs rhs)
;;; (fact datum)
;;; (data)
;;; (run)
;;; (see-rule rule)
;;;
;;; GLOBAL VARIABLES ARE:
;;; *rules*
;;; *facts*
(defun defrule (name lhs rhs)
(prog (rule)
(setq rule (gensym 'r))
(putprop rule name 'name)
(putprop rule (cdr (assoc 'patterns lhs)) 'patterns)
(putprop rule (cdr (assoc 'assert rhs)) 'assert)
(putprop rule (cdr (assoc 'delete rhs)) 'delete)
(setq *rules* (cons rule *rules*))))
;;; user adds a fact
(defun fact (datum)
(add-fact datum 'user))
(defun add-fact (datum origin)
(prog (fact)
(setq fact (gensym 'f))
(putprop fact datum 'datum)
(putprop fact origin 'origin)
(setq *facts* (cons fact *facts*))))
;;; print data in working memory
(defun data ()
(data2 *facts*))
(defun data2 (f)
(cond ((null f) nil)
(t (pr (get (car f) 'datum))
(data2 (cdr f)))))