ensure successfully functioning of simulate! with one propagator

This commit is contained in:
sorrel 2024-04-04 18:06:39 -04:00
parent d97bcfa82c
commit 02d2a56931

View file

@ -3,7 +3,6 @@
[prop-net.cell :as c]))
;; currently not implementing abort semantics
(defn- alerted-propagators* [] #{})
(defn- cells* [] {})
(defn- propagators-ever-alerted* [] #{})
@ -53,8 +52,6 @@
(defn- deref-get [rec key] (deref (key rec)))
;; TODO re-implementing with reference to PropNet
;; children should not make calls on each other, only return things to do?
(defrecord PropNet
[alerted-propagators
last-value-of-run
@ -72,8 +69,8 @@
(cell-key (get-cells net)))
(cell-content [net cell-key] (deref-get (get-cell net cell-key)
:content))
(propagator [net prop-key] (deref-get (propagators net)
prop-key))
(propagator [net prop-key] (prop-key (propagators net)))
;; mutation methods
(add-cell! [net cell-key]
(swap! (:cells net) assoc cell-key (c/make-cell))
@ -92,9 +89,23 @@
{:cell cur-cell})))
(catch Exception e
(prn e)))))
;; (add-propagator! [this prop-key func])
;; (add-neighbor-to-cell! [this cell-key propagator])
;; (add-output-to-propagator! [this prop-key cell])
(add-propagator! [this prop-key func]
(swap! (:all-propagators this) assoc prop-key (p/function->propagator func)))
(add-neighbor-to-cell! [this cell-key prop-key]
;; cell only needs to have its neighbors
;; c/new-neighbor! prop-key
(c/new-neighbor! (get-cell this cell-key) prop-key)
;; propagator needs to have the c/content wrapped in a lambda and have that added to its inputs
(p/add-input! (propagator this prop-key) (fn [] (c/content (get-cell this cell-key))))
:ok
)
(add-output-to-propagator! [this prop-key cell-key]
(let [output-setter
;; need to add content from the net in order to alert propagators
;; further down the network
(fn [new-content] (add-content-to-cell! this cell-key new-content))]
(p/add-output! (propagator this prop-key)
output-setter)))
;; run methods
(last-value-of-run [net] (deref-get net :last-value-of-run))
@ -103,9 +114,14 @@
(reset! (:last-value-of-run this) done)
(reset! (:propagators-ever-alerted this) propagators-ever-alerted*)
:ok)
;; (simulate! [net])
(simulate! [net]
(run! (fn [prop-key]
(do (swap! (:alerted-propagators net) disj prop-key)
(p/apply! (propagator net prop-key))))
(vec (get-alerted-propagators net))))
;; (halt! [net])
)
;; returns a propnet
(defn make-prop-net []
(map->PropNet
@ -126,7 +142,13 @@
(add-cell! this-net :5)
(add-cell! this-net :c*9)
(add-cell! this-net :9)
(add-cell! this-net :32+5)
(add-propagator! this-net :plusser +)
(add-neighbor-to-cell! this-net :32 :plusser)
(add-content-to-cell! this-net :32 32)
(add-neighbor-to-cell! this-net :5 :plusser)
(add-content-to-cell! this-net :5 5)
(add-output-to-propagator! this-net :plusser :32+5)
this-net))
(defn -main []