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 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