Nice! I think this kind of functionality should end up getting
promoted. I have also written this a couple of times and thought about
generalizing it. I'm glad you did.

This could also serve as the basis for some nice tracing functionality
(esp. combined the clojure.contrib.logging). You'd want to wrap the
hook function with a macro that also captured the function name and
maybe arglist metadata.

Tom

P.S. But shouldn't it be called Robert Hookjure?

On Jun 10, 10:56 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> I just released this library for allowing functionality to be extended
> via plugins:
>
>     (use 'robert.hooke)
>
>     (defn examine [x]
>       (println x))
>
>     (defn microscope
>       "The keen powers of observation enabled by Robert Hooke allow
>       for a closer look at any object!"
>       [f x]
>       (f (.toUpperCase x)))
>
>     (defn doubler [f & args]
>       (apply f args)
>       (apply f args))
>
>     (defn telescope [f x]
>       (f (apply str (interpose " " x))))
>
>     (add-hook #'examine microscope)
>     (add-hook #'examine doubler)
>     (add-hook #'examine telescope)
>
>     (examine "something")
>     > S O M E T H I N G
>     > S O M E T H I N G
>
> Hooks are functions that wrap other functions. They receive the
> original function and its arguments as their arguments. Hook
> functions can wrap the target functions in binding, change the
> argument list, only run the target functions conditionally, or all
> sorts of other stuff.
>
> It was originally designed to be used for Leiningen plugins, but I
> realized the functionality was quite general, so I spun it off into
> its own library.
>
> Feedback welcome.
>
> -Phil

-- 
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

Reply via email to