Why isn't this enough for the problem? Elves and deer are entering
Santa's frontdoor 1 at a time, when there is three elves in the room,
santa instantly deals with them (resetting the number of elves to 0),
when there is 9 deer in the room, santa goes sleighing.
(def santa (agent {:elves 0 :deer 0}))
(defn add-deer [san]
(if (= (:deer san) 8) (prn "sleighing time!")
(assoc san :deer (inc (:deer san)))))
(defn add-elf [san]
(if (= (:elves san) 2) (assoc san :elves 0)
(assoc san :elves (inc (:elves san)))))
; still needs a thread that spits out (send santa add-elf) at
irregular intervals
; still needs a thread that spits out (send santa add-deer) at
irregular intervals
; where it says "sleighing time", we need to shutdown the other
threads, clear, or
; ignore whatever sends to santa are still queued up, and printout a
message
; saying that it is christmas time.
; but I don't know yet how to do those things, and it is time to head
for work ;).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---