Re: refs, agents and add-watch

2010-02-12 Thread MiltondSilva
@all: Thank you very much for the replies. My bottomless pit of ignorance must be quite annoying but, I can only hope one day to be in your position. (e.g. answering others questions) @ataggart: A different entity is supposed to change the refs when they go over/under some limit. It's just the way

Re: refs, agents and add-watch

2010-02-11 Thread ataggart
On Feb 11, 4:22 pm, MiltondSilva wrote: > I now have another problem. When I run this in the repl: > > (add-watch products :prodkey send-products) > (add-watch material :matkey ask-material) > (dump material products products-store) >   (loop [cnt 10] >     (map #(send % client-act) clients) >  

Re: refs, agents and add-watch

2010-02-11 Thread ataggart
>(e.g. the owner should be the only one to inc materials etc) What's so special about the inc function as opposed to any other function? >Also, ask-materials and send-products should > be call immediately after a certain threshold. ask-materials  != dec, > one decrements the other increments and

Re: refs, agents and add-watch

2010-02-11 Thread Timothy Pratley
On 12 February 2010 10:22, MiltondSilva wrote: > (add-watch products :prodkey send-products) > (add-watch material :matkey ask-material) > (dump material products products-store) >  (loop [cnt 10] >    (map #(send % client-act) clients) >    (map #(send % manufacture) artisans) >    (if (zero? cnt

Re: refs, agents and add-watch

2010-02-11 Thread MiltondSilva
I now have another problem. When I run this in the repl: (add-watch products :prodkey send-products) (add-watch material :matkey ask-material) (dump material products products-store) (loop [cnt 10] (map #(send % client-act) clients) (map #(send % manufacture) artisans) (if (zero? cnt

Re: refs, agents and add-watch

2010-02-11 Thread MiltondSilva
I'm using counterclockwise, clojure version 1.1.0. The exception stopped occurring I think I had to recompile the code. I structured the code this way because of the way the problem is formulated (e.g. the owner should be the only one to inc materials etc), yet, the more I look at it the more it s

Re: refs, agents and add-watch

2010-02-11 Thread ataggart
As Michael said, your original code works fine for me (running 1.2.0 master). user=> (do (send artisan manufacture) (println @material @products @products-store)) 4 3 2 nil user=> (do (send artisan manufacture) (println @material @products @products-store)) 3 0 6 nil user=> (do (send artisan manu

Re: refs, agents and add-watch

2010-02-10 Thread MiltondSilva
This solved the problem: (defn ask-material [a-key the-ref old-state new-state] (if (<= new-state 0) (dosync (alter material + (int (rand 10) (str "asked for materials")) When the function ask-materials is invoked, it updates the state of the agent that caused

Re: refs, agents and add-watch

2010-02-10 Thread Michał Marczyk
On 11 February 2010 02:50, MiltondSilva wrote: > I have this code: > > [snip] > > java.lang.RuntimeException: Agent has errors (repl-1:8) Your code works fine for me. To help you debug your problem: you can use (agent-errors artisan) to discover what the exception is about, clear-agent-errors to