Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 36 lines (28 sloc) 1.255 kb
5c68bc2 @cgrand Added agent-utils
cgrand authored
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
a4b8d24 @tomfaulhaber Beginning to add namespace documentation for all namespaces.
tomfaulhaber authored
15 (ns
7188a51 use the 1.2 metadata reader macro ^ instead of #^
Aaron Bedra and Stuart Halloway authored
16 ^{:author "Christophe Grande",
a4b8d24 @tomfaulhaber Beginning to add namespace documentation for all namespaces.
tomfaulhaber authored
17 :doc "Miscellaneous agent utilities
18 (note to other contrib members: feel free to add to this lib)",
19 }
20 clojure.contrib.agent-utils)
5c68bc2 @cgrand Added agent-utils
cgrand authored
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))))
Something went wrong with that request. Please try again.