On Tue, Jan 6, 2009 at 10:00 AM, wubbie <sunj...@gmail.com> wrote: > > Hi, > > I tried your example and some weird sequence generates > java.util.concurrent.RejectedExecutionException (NO_SOURCE_FILE:0) > > > Here is the scenario: > Clojure > user=> (def counter (agent 0)) > #'user/counter > user=> (send counter inc) > #<Agent clojure.lang.ag...@9e4585> > user=> @counter > 1
The part above isn't related to my example. > user=> (def my-agent (agent 1)) > #'user/my-agent > user=> (defn sleep-and-multiply [old-state ms] > (Thread/sleep ms) > (* old-state times)) > java.lang.Exception: Unable to resolve symbol: times in this context > (NO_SOURCE_FILE:7) This is missing the "times" parameter. > user=> ; > (defn sleep-and-multiply [old-state n ms] > (Thread/sleep ms) > (* old-state n)) > #'user/sleep-and-multiply This looks fine. You're just naming the parameter "n" instead of "times", but it works the same. > user=> (send-off my-agent sleep-and multiply 2 1500) > java.lang.Exception: Unable to resolve symbol: sleep-and in this > context (NO_SOURCE_FILE:12) You're missing a hyphen in "sleep-and-multiply". > user=> (send-off my-agent sleep-and- multiply 2 1500) > java.lang.Exception: Unable to resolve symbol: sleep-and- in this > context (NO_SOURCE_FILE:13) You've got a space in "sleep-and-multiply". > user=> (send-off my-agent sleep-and-multiply 2 1500) > #<Agent clojure.lang.ag...@9a99eb> > user=> (send-off my-agent sleep-and-multiply 3 1500) > #<Agent clojure.lang.ag...@9a99eb> > user=> (await my-agent) > nil > user=> (println "my-agent=" @my-agent) > my-agent= 6 > nil > user=> (shutdown-agents) > nil All this is correct! > user=> (def my-agent (agent 10)) Redefining the agent to start with a different value. > #'user/my-agent > user=> (defn sleep-and-multiply [old-state n ms] > (Thread/sleep ms) > (+ old-state n)) > #'user/sleep-and-multiply Why are you defining that function again? Oh I see. You're using addition instead of multiplication. > user=> (send-off my-agent sleep-and-multiply 7 1500) > java.util.concurrent.RejectedExecutionException (NO_SOURCE_FILE:0) I don't know why you're getting that error. > user=> (send-off my-agent sleep-and-multiply 3 1500) > #<Agent clojure.lang.ag...@3a5a9c> > user=> (send-off my-agent sleep-and-multiply 7 1500) > #<Agent clojure.lang.ag...@3a5a9c> > user=> (println "my-agent = " @my-agent) > my-agent = 10 > nil Yikes! I'm sure you expected the result to be 20. The value didn't get changed! I don't know why. > user=> (agent-errors my-agent) > nil > user=> (clear-agent-errors my-agent) > nil > user=> (println "my-agent = " @my-agent) > my-agent = 10 > nil > user=> (send-off my-agent sleep-and-multiply 7 1500) > #<Agent clojure.lang.ag...@3a5a9c> > user=> (println "my-agent = " @my-agent) > my-agent = 10 > nil > user=> (send-off my-agent sleep-and-multiply 3 1500) > #<Agent clojure.lang.ag...@3a5a9c> > user=> (println "my-agent = " @my-agent) > my-agent = 10 > nil Does anyone know why the value of the agent isn't getting changed? -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---