I found my problem.  I wasn't calling agents.  I was doing this.

=> (defn next-agent [] (nth agents (next-counter)))

and should have been doing this.

=> (defn next-agent [] (nth (agents) (next-counter)))

Still, I would like feedback.  Is there a cleaner way to do this?

Thanks.
Justin

On Wed, Jan 14, 2009 at 9:33 AM, Justin Johnson <ajustinjohn...@gmail.com>wrote:

> Hello,
>
> I'm trying to create a list of agents and a function called next-agent that
> always gives me the next agent and restarts at the beginning when the list
> is exhausted.  For my purposes the agent is serving as a thread that will do
> some work.  I don't much care about its value at this time.
>
> I'm new to Clojure and am pretty sure there is an elegant way to do what I
> want, but my little OO head is spinning.  Any help you can provide is
> appreciated.
>
> Thanks,
> Justin
>
>
> => (def counter (ref 0))
> #'user/counter
> => (defn next-counter [] (dosync (alter counter inc)))
> #'user/next-counter
> => (def a1 (agent 0))
> #'user/a1
> => (def a2 (agent 0))
> #'user/a2
> => (def a3 (agent 0))
> #'user/a3
> => (defn agents [] (cycle [a1 a2 a3]))
> #'user/agents
> => (defn next-agent [] (nth agents (next-counter)))
> #'user/next-agent
> => (next-agent)
> java.lang.UnsupportedOperationException: nth not supported on this type:
> user$agents__1177 (repl-1:92)
>
>
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to