+1 On Wednesday, November 25, 2015 at 8:14:32 AM UTC-5, Colin Yates wrote: > > <syntax-police>(let [x …] (if x true false)) is exactly what (if-let [x …] > true false) is for ( > http://stackoverflow.com/questions/2010287/when-to-use-let-vs-if-let-in-clojure > )</syntax-police> > > :-) > > On 25 Nov 2015, at 13:10, William la Forge <lafo...@gmail.com > <javascript:>> wrote: > > James, > > I've been thinking about protocols. Yes, I can now put them on an > aggregate, but there may be a lot of places where it is better not to use a > protocol and just use functions instead. > > The code below does not use a protocol and I rather like it. In other > cases we can use functions to achieve indirection by calling functions in > an aggregate. So it remains to be seen if there is a good case for using a > protocol with an aggregate. But at least I know how now--create an > aggregate in a record. > > Bill > > (ns aatree.closer-trait > (:require [clojure.tools.logging :as log])) > > (set! *warn-on-reflection* true) > > (defn on-close [this f] > (let [fsa (:closer-fsa this)] > (if fsa > (do > (swap! fsa > (fn [fs] > (if fs > (conj fs f) > (atom (list f))))) > this) > (assoc this :closer-fsa (atom (list f)))))) > > (defn- do-closer [this fs] > (when fs > (try > ((first fs) this) > (catch Exception e > (log/warn e "exception on close"))) > (recur this (next fs)))) > > (defn do-close [this] > (let [fsa (:closer-fsa this)] > (if fsa > (let [fs @fsa] > (if fs > (if (compare-and-set! fsa fs nil) > (do-closer this fs) > (recur this))))))) > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@googlegroups.com <javascript:> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+u...@googlegroups.com <javascript:> > 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+u...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > >
-- 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.