(let ((memos (make-hash-table :test #'equal)) (depends (make-hash-table :test #'equal))) (defstruct cell (name #'(lambda (c) (gensym "CELL"))) (ifneeded #'(lambda (c) (gensym "CELL"))) (ifadded #'identity) (ifread #'identity) ifupdated ifremoved (memos memos) (depends depends) cached uses (ok? #'ok))) (defun def (name ) ) (defmethod access ((c cell)) (cell-access c)) (defmethod access ((x t)) x) (set-macro-character #\! #'(lambda (stream char) (declare (ignore char)) (access (read stream t nil t)))) (defun cell-access (c) (unless (cell-cached c) (fill-cell c)) (readz c) (cell-cache c)) (defun cell-fill (c) (dolist (depend (cell-depends c)) (cell (let ((new (ok? (needz c)))) (setf (cell-cache c) new (cell-cached c) t) (addz c))) (defun cell-empty (c) (let ((old (cell-cache c))) (removez c) (setf (cell-cache c) nil (cell-cached c) nil) old)) (defmacro addz (c) `(funcall (cell-ifadded ,c))) (defmacro needz (c) `(funcall (cell-ifneeded ,c))) (defmacro readz (c) `(funcall (cell-ifread ,c))) (defmacro removez (c) `(funcall (cell-ifremoved ,c))) (defmacro ok? (c) `(funcall (cell-ok? ,c))) (defun ok (x) (declare (ignore x)) t)