Posted By

narkisr on 03/27/09


Tagged

trace clojure AOP


Versions (?)

AOP tracing in clojure


 / Published in: Lisp
 

Shows how its possible to do AOP like programing in clojure.

  1. (defn trace-wrap [v]
  2. (let [f (var-get v)
  3. fname (:name ^v)]
  4. (fn [& args]
  5. (println "calling" fname)
  6. (let [rtn (apply f args)]
  7. (println "done with" fname)
  8. rtn))))
  9.  
  10. (defn add [x y]
  11. (println "adding" x "and" y)
  12. (+ x y))
  13.  
  14. (prn (add 4 5))
  15.  
  16. (defmacro trace-fn [v & body]
  17. `(binding [~v (trace (var ~v))]
  18. ~@body))
  19.  
  20. (trace-fn add
  21. (prn (add 4 5)))

Report this snippet  

You need to login to post a comment.