Looks nice. It's pretty similar to Robert Hooke though -- which is more
of an advice library than a hook library despite it's name. 

Edwin Watkeys <e...@poseur.com> writes:

> Hello,
>
> Richelieu, a library for advising functions, is in something resembling 
> announcement-worthy shape. It's available at the following URL:
>
> http://github.com/thunknyc/richelieu
>
> During my experience writing thunknyc/profile and the associated CIDER 
> support, I realized that advising or decorating functions is something 
> that's been getting reinvented over and over. I wanted to put an end to 
> that. Richelieu supports advising functions as well as vars and namespaces. 
> Multiple advise functions can be associated with a function, and advise 
> functions have access to the underlying var or function this is being 
> decorated. Below is an edited sample from the README that shows how to 
> implement tracing advice using the library.
>
> I hope this may be useful to one or more people out there. I plan on 
> modifying thunknyc/profile to use Richelieu as part of a push to implement 
> additional profiling modalities.
>
> Regards,
> Edwin
>
> (require '[richelieu.core :refer [advice advise-ns
>                                   *current-advised*
>                                   defadvice]])
>
> ;;; Here are some simple functions.
> (defn add [& xs] (apply + xs))
> (defn mult [& xs] (apply * xs))
> (defn sum-squares [& xs]
>   (apply add (map #(mult % %) xs)))
>
> ;;; This tracing advice shows how to get the current advised object,
> ;;; which can either be a var or a function value, depending on the
> ;;; context in which the advice was added.
> (def ^:dynamic *trace-depth* 0)
>
> (defn- ^:unadvisable trace-indent []
>   (apply str (repeat *trace-depth* \space)))
>
> (defadvice trace
>   "Writes passed arguments and passes them to underlying
>   function. Writes resulting value before returning it as result."
>   [f & args] 
>   (printf "%s> %s %s\n" (trace-indent) *current-advised* args)
>   (let [res (binding [*trace-depth* (inc *trace-depth*)]
>               (apply f args))]
>     (printf "%s< %s %s\n" (trace-indent) *current-advised* res)
>     res))
>
> (advise-ns 'user trace)
>
> (sum-squares 1 2 3 4)
> ;;; The above invocation produces the following output:
>
> ;; > #'user/sum-squares (1 2 3 4)
> ;;  > #'user/mult (1 1)
> ;;  < #'user/mult 1
> ;;  > #'user/mult (2 2)
> ;;  < #'user/mult 4
> ;;  > #'user/mult (3 3)
> ;;  < #'user/mult 9
> ;;  > #'user/mult (4 4)
> ;;  < #'user/mult 16
> ;;  > #'user/add (1 4 9 16)
> ;;  < #'user/add 30
> ;; < #'user/sum-squares 30

-- 
Phillip Lord,                           Phone: +44 (0) 191 208 7827
Lecturer in Bioinformatics,             Email: phillip.l...@newcastle.ac.uk
School of Computing Science,            
http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower,               skype: russet_apples
Newcastle University,                   twitter: phillord
NE1 7RU                                 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to