Note that there are some explanatory texts on larger screens.

plurals
  1. POClojure, Agent, lack side-effects
    primarykey
    data
    text
    <p>I'm using agents to manipulate a structure, but I don't have all my side effects. </p> <p>All the messages are sent(I've printed and counted them), but there are times when I don't have all my side-effects. As if not all of my functions were applied on the agent's state, or if the last send is applied on a previous state.. </p> <p>I experimented with doall, dorun but haven't find a solution, appreciate any help.</p> <pre><code>;; aux function for adding an element to a hashmap (defn extend-regs [reg s o] (let [os (get reg s)] (if (nil? os) (assoc reg s [o]) (assoc reg s (conj os o))))) ;; the agent's altering function - adding an element to the :regs field(a hashmap) (defn add-reg! [d s o] (send d (fn [a] (assoc a :regs (extend-regs (:regs a) s o))))) ;; Creating the agents, dct/init returns an agent ;; pds: data for fields (defn pdcts-&gt;init-dcts! [pds] (doall (map dct/init (map :nam pds) (repeat nil)))) ;; Altering one agent's state, dct/add-reg sends an assoc message to the agent ;; d: agent, pd: data for fields (defn dct-&gt;add-regs! [d pd] (dorun (map (fn [s r] (dct/add-reg! d s r)) (:syms pd) (:regs pd))) d) ;; Going through all agents ;; ds: agents, pds: datas (defn dcts-&gt;add-regs! [ds pds] (dorun (map (fn [d pd] (dct-&gt;add-regs! d pd)) ds pds)) ds) </code></pre> <p>EDIT: =====================================================</p> <p>Okay it turned out I just haven't wait enough to my threads to finish their tasks. Now the question is how can I monitor my agents. How can I know that there are unfinished threads in the queue? I've only found swank.core/<em>active-threads</em> and similar ones but they are not a solution. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload