From c9f422bc85573f427e21f657c0fdbecc4ab57d83 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 14 Apr 2010 17:00:15 -0600 Subject: [PATCH] working -- with less debug cruft --- propagator.org | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/propagator.org b/propagator.org index 4308c0d..9c37832 100644 --- a/propagator.org +++ b/propagator.org @@ -13,15 +13,12 @@ :license "GPLV3", :doc "Simple concurrent propagator system."} propagator - (:use clojure.contrib.repl-utils - clojure.contrib.duck-streams)) + (:use clojure.contrib.repl-utils)) (defmacro cell "Define a new cell." [name state] `(def ~name (agent ~state))) - (def que (ref '())) - (defmacro propagator "Define a new propagator." [name in-cells out-cells & body] `(do @@ -36,21 +33,15 @@ "Run a propagator, first collect the most recent values from all cells associated with the propagator, then evaluate." [propagator] - `(let [output-val# (apply ~propagator (map deref (:in-cells ^#'~propagator))) - output-cells# (:out-cells ^#'~propagator)] - (append-spit "/home/eschulte/Desktop/spitoon" - (format "results in %S\n" output-val#)) - (append-spit "/home/eschulte/Desktop/spitoon" - (format "sending to %S\n" output-cells#)) - (doseq [cell# output-cells#] - (send cell# (fn [_#] output-val#))))) + `(let [run-me# (fn [_#] + (apply ~propagator (map deref (:in-cells ^#'~propagator))))] + (map (fn [cell#] (send cell# run-me#)) (:out-cells ^#'~propagator)))) (defmacro add-neighbor "Add a neighbor to the given cell." [cell neighbor] `(add-watcher ~cell :send - (agent nil :validator - (fn [_#] (dosync (run-propagator ~neighbor)) true)) + (agent nil :validator (fn [_#] (do (future (run-propagator ~neighbor)) true))) (fn [_# _#]))) #+end_src -- 2.11.4.GIT