Thank you for pointing that out. I notice your style is similar to Rich's in his ant.clj [1] which seems like the kind of solution that might be used in other functional and/or lisp languages. Do you know if that's the case with self-calling functions and agents? However, isn't there more overhead with calls to send-off instead of recur?
I understand functions sent to an agent will only run one at a time, fifo-style, but was under the impression *agent* was for the current "main" thread of the program. Does *agent* instead refer to whatever is the current thread in the function's runtime context? Hope that question makes sense. [1] http://clojure.googlegroups.com/web/ants.clj?gda=uyYClToAAADrLV-d6p24hYFcam_S99IgeBuuRL78NgAsI-ljfFHCWu9OU0NQiFWgQuhmPR7veGf97daDQaep90o7AOpSKHW0 On Tue, Jun 15, 2010 at 3:03 PM, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > besides the answer you got from Shawn, I'd like to question your use of the > agent system. This is not the way it is supposed to be used. To model a > processing loop with agents you should send the action back to the agent > itself. > > (def running? (atom true)) > > (defn process > [agent-state step] > (when @running? > (send-off *agent* process (inc step))) > (+ agent-state step)) > > (def a (agent 0)) > (send-off a process 1) > (Thread/sleep 100) > (reset! running? false) > > Note: in an action *agent* refers to the current agent. > > Sincerely > Meikel > -- 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 Note that posts from new members are moderated - please be patient with your first post. 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