On Sat, Nov 8, 2008 at 10:23 PM, Stuart Halloway
<[EMAIL PROTECTED]> wrote:
>
> How about:
>
> (defn runonce
> "Create a function that will only run its argument once."
> [function]
> (let [call-count (ref 0)]
> (fn [& args]
> (when (= 1 (dosync (alter call-count inc)))
> (apply function args)))))
Or:
(defn runonce
"Create a function that will only run its argument once."
[function]
(let [needed (java.util.concurrent.atomic.AtomicBoolean. true)]
(fn [& args]
(when (.getAndSet needed false)
(apply function args)))))
--Chouser
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---