/ Published in: Lisp
Shows how its possible to do AOP like programing in clojure.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(defn trace-wrap [v] (let [f (var-get v) fname (:name ^v)] (fn [& args] (println "calling" fname) (let [rtn (apply f args)] (println "done with" fname) rtn)))) (defn add [x y] (println "adding" x "and" y) (+ x y)) (prn (add 4 5)) (defmacro trace-fn [v & body] `(binding [~v (trace (var ~v))] ~@body)) (trace-fn add (prn (add 4 5)))