On Dec 6, 9:22 pm, Allen Rohner <aroh...@gmail.com> wrote:
> > What is it supposed to do?  What's the usage look like?
>
> Oh right, a description would be useful. The point is to build up the
> functionality of a function from several places. You define a hook
> function:
>
> (defhook foo [a b])
>
> Initially, it does nothing. Then, other code can add hooks:
>
> (add-hook foo :first-hook (fn [a b] (println "first!")))
>
> The hooks should all have the same signature as in defhook. You can
> add as many as you like. The second argument is a "name", so you can
> remove the hook later if desired.
>
> (add-hook foo :second (fn [a b] (println "a=" a "b=" b)))
>
> Then, call the function, and all of the hooks get called in the order
> added
>
> user> (foo 1 2)
> first!
> a= 1 b= 2
> nil
>
> There's also a function, remove-hook, that works about the way you'd
> expect.
> (remove-hook foo :first-hook)
>
> > Why does defhook's signature arg never get used?
> > It'd also help readability to wrap your doc string.
>
> This is just a sketch. I meant for the signature to go into the
> arglist metadata of the def'd var, but couldn't get it to work in 5
> minutes, and gave up on it (for now). I plan on doing all of that
> polishing, assuming nobody tells me it's not evil. Honestly, I'm not
> sure yet, but it seems to work well for Emacs, and I couldn't think of
> a better alternative for my own Clojure problem.
>
> Allen

Hmm.  A few observations:

- You can only compose side-effect-only functions that can't interact
with each other.  I could see that being useful for stuff like trace
logging, but even in those cases there's an initial function with its
own utility (and returne value).  This is basically a loosely
constructed do block.

- The behavior is a bit "magical" as regards to who adds stuff, though
I guess that's not too different from defmulti.

- Maps vs vector-of-vector, dealing with duplicate identifiers, etc.

What was the actual usage scenario that drove this?

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