;;;; utils ;;; about symbols (defun thingp (x y) (and (symbolp x) (find y (symbol-name x)))) (defun goalp (x) (thingp x (wme-goal *w*))) (defun nump (x) (thingp x (wme-num *w*))) (defun knownp (x) (not (eql x (wme-unknown *w*)))) ;;; misc (defun zero (l) (declare (ignore l)) 0) (defun noop (&rest l) (declare (ignore l)) t) ;;;; main ;;; reader (defun data (&optional f) (w0) (load (or f (thefile))) (funcall (wme-ready *w*)) (funcall (wme-run *w*)) (funcall (wme-report *w*)) ) (defmacro deftable (name &rest cols) `(setf (wme-table *w*) (make-table :name ',name :cols (mapcar #'make-col ',cols)))) (defun make-col (col) (if (nump col) (make-num :name col :goalp (goalp col)) (make-sym :name col :goalp (goalp col)))) (defun sort-rows () (setf (therows) (sort (therows) #'< :key #'row-sortkey))) (defun defklass (class &optional (tbl (thetable))) (let ((k (first (member class (theklasses tbl) :key #'klass-name)))) (unless k (setf (theklasses tbl) (appendl (theklasses tbl) (setf k (make-klass :name class))))) k)) (defun defrow (l &optional (tbl (thetable)) &aux (class (if (> (car (goals-in-list l)) 0) "defective" "flawless"))) (incf (klass-n (defklass class tbl))) (push (make-row :cells l :class class :utility (funcall (theu) class) :sortkey (+ (randf 0.49) (position class (theklasses tbl) :key #'klass-name))) (therows tbl))) (defun goals-in-list (l) (mapcan #'1goal-in-list l (thecols))) (defun 1goal-in-list (x c) (and (col-goalp c) (knownp x) (list x)))