(defstruct best (max 20) sorted (n 0)) (defstruct store name (best (make-best :n 20)) rest (cols 0) names) (defparameter *store* (make-store)) (defun final (l) (first (last l))) (let ((get0 #'final)) (defun bout (x cache &optional (get get0)) (< (funcall get x) (funcall get (first (best-sorted cache))))) (defun bin (x cache &optional (get get0)) (or (not (bout x cache get)) (member x (best-sorted cache) :key get))) (defun badd (new cache &optional (get get0)) (setf (best-sorted cache) (oinsert new get (best-sorted cache))) (if (< (best-n cache) (best-max cache)) (incf (best-n cache)) (pop (best-sorted cache))) cache) ) (defun oinsert (new access old) (cond ((null old) (list new)) ((<= (funcall access new) (funcall access (first old))) (cons new old)) (t (cons (first old) (oinsert new access (rest old)))))) (defun demo-add () (let ((b (make-best :max 3)) out) (dotimes (i 50 b) (let ((next `(x ,(random 1000)))) (push next out) (badd next b))) (sort out #'< :key #'second) (print out) b)) (defmacro data (&rest l) `(data1 ',l)) (defun data1 (l) (badd l (store-best *store*))) (defmacro attribute (&rest l) `(attribute1 ',l)) (defun attribute1 (l) (push (first l) (store-names *store*)) (incf (store-cols *store*))) (defmacro defrelation (name &rest l) `(defun ,name () (let ((*store* (make-store :name ',name))) ,@l *store* ))) ;(if (yes-or-no-p "compile?") (load "sensory.lisp"))