comparison 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
comparison
equal deleted inserted replaced
9:35cf337adfcf 10:ef7dbbd6452c
1 ; Copyright (c) Christophe Grand, November 2008. All rights reserved.
2
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.
10
11 ;; misc agent utilities
12
13 ;; note to other contrib members: feel free to add to this lib
14
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)
21
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.
25
26 Example:
27 (capture-and-send [*out*] a f b c)"
28
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))))