On Dec 28, 2008, at 9:58 AM, Mark Volkmann wrote:

Are you sure the code below works? It doesn't work for me with the
revision 1185. For me it outputs:

#<Agent clojure.lang.ag...@355a47>
0

and stops.

A change to Clojure's behavior at r1158 caused my incorrect (or at least iffy) code break instead of working. I'm guessing that when I posted I hadn't yet updated past r1158 on that computer. Here's the session showing how I confirmed what you were seeing and found and fixed the problem. It includes corrected code and shows it working with r1185.

--Steve

Clojure
1:1 user=> (def my-agent (agent 0))
#'user/my-agent
1:2 user=> (defn update [old-state] (prn old-state) (.sleep Thread 1000)
(send-off *agent* update) (inc old-state))
#'user/update
1:4 user=> (send-off my-agent update)
0
#<Agent clojure.lang.ag...@75f172aa>
1:5 user=>
1:6 user=>
1:7 user=>
1:8 user=> (send-off my-agent update)
java.lang.Exception: Agent has errors (repl-1:8)
1:9 user=> (agent-errors my-agent)
(#<IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: sleep for class java.lang.Class>)
1:10 user=> (defn update [old-state] (prn old-state) (Thread/sleep 1000)
(send-off *agent* update) (inc old-state))
#'user/update
1:12 user=> (send-off my-agent update)
java.lang.Exception: Agent has errors (repl-1:12)
1:13 user=> (clear-agent-errors my-agent)
nil
1:14 user=> (send-off my-agent update)
#<Agent clojure.lang.ag...@75f172aa>
1:15 user=> 0
1
2
3
4
5

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to