This seems to be true:

"I would have to say that the biggest surprise is how little they're needed 
in Clojure."

Run this search on Google: 

agent send clojure site:github.com

The first 5 pages point me to examples from several years ago, or error 
reports, or unit tests. Nothing substantial or recent. I think it is 
interesting how many of the results are blog posts or gists -- people talk 
about agents much more then they actually use them. 

Still, there are some examples: 

https://github.com/aphyr/riemann/blob/302cff942f308771b1d8d837cdf9ce2c9090daed/src/riemann/pool.clj

(defmacro with-pool "Evaluates body in a try expression with a symbol 
'thingy claimed from the given pool, with specified claim timeout. Releases 
thingy at the end of the body, or if an exception is thrown, invalidates 
them and rethrows. Example: ; With client, taken from connection-pool, 
waiting 5 seconds to claim, send ; client a message. (with-pool [client 
connection-pool 5] (send client a-message))" [[thingy pool timeout] & body] ; 
Destructuring bind could change nil to a, say, vector, and cause ; 
unbalanced claim/release. `(let [thingy# (claim ~pool ~timeout) ~thingy 
thingy#] (try (let [res# (do ~@body)] (release ~pool thingy#) res#) (catch 
Throwable t# (invalidate ~pool thingy#) (throw t#)))))



And:

https://github.com/clojure/java.jmx/blob/master/src/main/clojure/clojure/java/jmx.clj


(deftype Bean [state-ref] DynamicMBean (getMBeanInfo [_] (MBeanInfo. (.. _ 
getClass getName) ; class name "Clojure Dynamic MBean" ; description (
map->attribute-infos @state-ref) ; attributes nil ; constructors nil ; 
operations nil)) (getAttribute [_ attr] (@state-ref (keyword attr))) (
getAttributes [_ attrs] (let [result (AttributeList.)] (doseq [attr attrs] (
.add result (Attribute. attr (.getAttribute _ attr)))) result)) (
setAttribute [_ attr] (let [attr-name (.getName attr) attr-value (.getValue 
attr) state-update {(keyword attr-name) attr-value}] (condp = (type 
state-ref) clojure.lang.Agent (await (send state-ref (fn [state 
state-update] (merge state state-update)) state-update)) clojure.lang.Atom (
swap! state-ref merge state-update) clojure.lang.Ref (dosync (ref-set 
state-ref (merge @state-ref state-update)))))) (setAttributes [_ attrs] (let 
[attr-names (map (fn [attr] (.setAttribute _ attr) (.getName attr)) attrs)] 
(.getAttributes _ (into-array attr-names)))))



I would love to see some other examples.




 

On Wednesday, May 6, 2015 at 9:49:47 PM UTC-4, Surgo wrote:
>
> I'm not saying this is everyone's experience or anything, but at times I 
> have at times considered some deeper STM-work with agents but I could not 
> seem to penetrate the documentation at the time. I do not know if it's 
> different now
>
> -- Morgon
>
> On Wednesday, May 6, 2015 at 5:38:08 PM UTC-4, James Reeves wrote:
>>
>> On 6 May 2015 at 21:58, Alex Miller <al...@puredanger.com> wrote:
>>
>>> I would have to say that the biggest surprise is how little they're 
>>> needed in Clojure. The combination of immutable data, functions to update 
>>> complex data structures, and fast pure function updates with atoms actually 
>>> satisfies a large percentage of real use cases.
>>>
>>
>> I'll echo this. I've been using Clojure for years, and I can't recall 
>> ever needing refs (or agents for that matter).
>>
>> - James
>>
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to