Hi Stuart,

the code didn't run for me.

On Oct 28, 3:06 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> ; guess pi by running Monte Carlo simulation count times
> ; spread across n agents
> (defn guess-pi-agent [n count]
>    (let [count (quot count n)
>         agents (for [_ (range n)] (agent count))]
>      (doseq a agents (send a sample-for-pi))
>      (apply await agents)
>      (guess-from-samples (reduce (fn [a1 a2]
>                                   {:in (+ (:in @a1) (:in @a2))
>                                    :total (+ (:total @a1) (:total @a2))})
>                                 agents))))

Shouldn't the function which is given as argument to reduce return an
object of the same type as it expects as its first input parameter?
Here the function takes two agents and returns a map.  The following
works for me:

(defn guess-pi-agent [n count]
  (let [count (quot count n)
        agents (for [_ (range n)] (agent count))]
    (doseq a agents (send a sample-for-pi))
    (apply await agents)
    (guess-from-samples (reduce
                         (fn [m a]
                           {:in (+ (:in m) (:in @a))
                            :total (+ (:total m) (:total @a))})
                         {:in 0 :total 0}
                         agents))))

Greetings,
Stephan
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to