aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clojure/contrib/test_contrib/test_trace.clj6
-rw-r--r--src/clojure/contrib/trace.clj15
2 files changed, 19 insertions, 2 deletions
diff --git a/src/clojure/contrib/test_contrib/test_trace.clj b/src/clojure/contrib/test_contrib/test_trace.clj
index 4b283056..dee7122a 100644
--- a/src/clojure/contrib/test_contrib/test_trace.clj
+++ b/src/clojure/contrib/test_contrib/test_trace.clj
@@ -9,4 +9,8 @@
(deftest test-tracing-a-function-that-calls-itself
(let [output (with-out-str (call-myself 1))]
(is (re-find #"^TRACE t\d+: (call-myself 1)\nTRACE t\d+: | (call-myself 0)\nTRACE t\d+: | => nil\nTRACE t\d+: => nil$"
- output)))) \ No newline at end of file
+ output))))
+
+(deftest dotrace-on-core
+ (let [output (with-out-str (dotrace [mod] (mod 11 5)))]
+ (is (re-find #"\(mod 11 5\)" output))))
diff --git a/src/clojure/contrib/trace.clj b/src/clojure/contrib/trace.clj
index 1ac00a70..ccfc5ef1 100644
--- a/src/clojure/contrib/trace.clj
+++ b/src/clojure/contrib/trace.clj
@@ -32,7 +32,7 @@
(ns
- #^{:author "Stuart Sierra",
+ #^{:author "Stuart Sierra, Michel Salim",
:doc "This file defines simple \"tracing\" macros to help you see what your
code is doing."}
clojure.contrib.trace)
@@ -83,3 +83,16 @@ code is doing."}
(defn ~name [& args#]
(trace-fn-call '~name f# args#)))))
+(defmacro dotrace
+ "Given a sequence of function identifiers, evaluate the body
+ expressions in an environment in which the identifiers are bound to
+ the traced functions. Does not work on inlined functions,
+ such as clojure.core/+"
+ [fns & exprs]
+ (if (empty? fns)
+ `(do ~@exprs)
+ (let [func (first fns)
+ fns (next fns)]
+ `(let [f# ~func]
+ (binding [~func (fn [& args#] (trace-fn-call '~func f# args#))]
+ (dotrace ~fns ~@exprs))))))