view src/clojure/contrib/agent_utils.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line source
1 ; Copyright (c) Christophe Grand, November 2008. All rights reserved.
3 ; The use and distribution terms for this software are covered by the
4 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 ; which can be found in the file epl-v10.html at the root of this
6 ; distribution.
7 ; By using this software in any fashion, you are agreeing to be bound by
8 ; the terms of this license.
9 ; You must not remove this notice, or any other, from this software.
11 ;; misc agent utilities
13 ;; note to other contrib members: feel free to add to this lib
15 (ns
16 ^{:author "Christophe Grande",
17 :doc "Miscellaneous agent utilities
18 (note to other contrib members: feel free to add to this lib)",
19 }
20 clojure.contrib.agent-utils)
22 (defmacro capture-and-send
23 "Capture the current value of the specified vars and rebind
24 them on the agent thread before executing the action.
26 Example:
27 (capture-and-send [*out*] a f b c)"
29 [vars agent action & args]
30 (let [locals (map #(gensym (name %)) vars)]
31 `(let [~@(interleave locals vars)
32 action# (fn [& args#]
33 (binding [~@(interleave vars locals)]
34 (apply ~action args#)))]
35 (send ~agent action# ~@args))))