;; -*- Mode: Lisp; -*- ;;;; tre interface ;;; Copyright (c) 1993, Kenneth D. Forbus, Northwestern University, ;;; and Johan de Kleer, the Xerox Corporation. ;;; All rights reserved. ;;; See the file legal.txt for a paragraph stating scope of permission ;;; and disclaimer of warranty. The above copyright notice and that ;;; paragraph must be included in any separate copy of this file. (in-package :cl-user) ;; Includes user hooks (for people and programs). (defstruct (tre (:print-function tre-printer)) title ; String for printing (dbclass-table nil) ; symbols --> classes (debugging nil) ; prints extra info if non-nil (queue nil) ; LIFO (rule-counter 0) ; Unique id for rules (rules-run 0)) ; Statistics (defun tre-printer (tre st ignore) "Print representation of tre struct." (declare (ignore ignore)) (format st "" (tre-title tre))) (proclaim '(special *tre*)) ;; Current tre (defvar *tre* nil "Name for default tre") (defmacro with-tre (tre &rest forms) "Within scope of statement, use tre as default tre." `(let ((*tre* ,tre)) ,@ forms)) (defun in-tre (tre) "Set the default tre to a new value." (setq *tre* tre)) (defmacro debugging-tre (msg &rest args) "Print message if debugging turned on for default tre." `(when (tre-debugging *tre*) (format t ,msg ,@ args))) (defun create-tre (title &key debugging) "create a new tiny rule engine." (make-tre :title title :dbclass-table (make-hash-table :test #'eq) :debugging debugging)) (defun debug-tre (tre debugging) "Set debugging for this tre." (setf (tre-debugging tre) debugging)) ;;;; Drivers for programs and people (defun run (&optional (*tre* *tre*)) (format T "~%>>") (do ((form (read) (read))) ((member form '(quit stop exit q QUIT Q x X)) nil) (format t "~%~A" (eval form)) (run-rules *tre*) ;; Defined in RULES module (format t "~%>>"))) (defun run-forms (*tre* forms) ;; Toplevel for programs (dolist (form forms) (eval form) (run-rules *tre*))) (defun show (&optional (stream *standard-output*)) "Show the current data and rules for the default tre." ;; Pass on the request to both modules of default tre (show-data stream) (show-rules stream))