I have this code:
(def material (ref 2))
(def products-store (ref 2))
(def products (ref 0))
(def artisan (agent "idle"))
(defn manufacture [state]
(dosync
(alter material dec)
(alter products inc))
(str "idle"))
(defn ask-material [a-key the-ref old-state new-state]
(if (<= new-state 0)
(dosync (alter material + (int (rand 10))))))
(defn send-products [a-key the-ref old-state new-state]
(if (>= new-state 4)
(dosync
(alter products - new-state)
(alter products-store + new-state))))
when I evaluate this:
(add-watch products :prodkey send-products)
(add-watch material :matkey ask-material)
(send artisan manufacture)
(send artisan manufacture)
(send artisan manufacture)
(send artisan manufacture)
java.lang.RuntimeException: Agent has errors (repl-1:8)
I'm clearly missing something but I have no idea what, if someone
could point me in the right direction I would be very grateful.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en