Mercurial > lasercutter
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 the4 ; 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 this6 ; distribution.7 ; By using this software in any fashion, you are agreeing to be bound by8 ; the terms of this license.9 ; You must not remove this notice, or any other, from this software.11 ;; misc agent utilities13 ;; note to other contrib members: feel free to add to this lib15 (ns16 ^{:author "Christophe Grande",17 :doc "Miscellaneous agent utilities18 (note to other contrib members: feel free to add to this lib)",19 }20 clojure.contrib.agent-utils)22 (defmacro capture-and-send23 "Capture the current value of the specified vars and rebind24 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))))