1.2.0 permalink Arrow_down_16x16
  • (deftrace name & definition)
Use in place of defn; traces each call/return of this fn, including
arguments. Nested calls to deftrace'd functions will print a
tree-like structure.

1 Example top

  • ;;Example courtesy to Jonas Enlund on clojure@googlegroups.com 2011-12-30:
    
    (ns trc.core
     (:use [clojure.tools.trace :only [deftrace]]))
    
    (deftrace fib [n]
     (if (or (= n 0) (= n 1))
         1
         (+ (fib (- n 1)) (fib (- n 2)))))
    
    the following is printed when (fib 4) is evaluated:
    
    TRACE t2302: (fib 4)
    TRACE t2303: | (fib 3)
    TRACE t2304: | | (fib 2)
    TRACE t2305: | | | (fib 1) 
    TRACE t2305: | | | => 1
    TRACE t2306: | | | (fib 0)
    TRACE t2306: | | | => 1
    TRACE t2304: | | => 2
    TRACE t2307: | | (fib 1)
    TRACE t2307: | | => 1
    TRACE t2303: | => 3
    TRACE t2308: | (fib 2)
    TRACE t2309: | | (fib 1)
    TRACE t2309: | | => 1
    TRACE t2310: | | (fib 0)
    TRACE t2310: | | => 1
    TRACE t2308: | => 2
    TRACE t2302: => 5
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/trace.clj:75 top

(defmacro deftrace
  "Use in place of defn; traces each call/return of this fn, including
  arguments.  Nested calls to deftrace'd functions will print a
  tree-like structure."
  [name & definition]
  `(do
     (def ~name)
     (let [f# (fn ~@definition)]
       (defn ~name [& args#]
         (trace-fn-call '~name f# args#)))))
Vars in clojure.contrib.trace/deftrace: defmacro name apply concat defn fn let list seq vector
Used in 0 other vars

Comments top

No comments for deftrace. Log in to add a comment.