On 10.05.2013 14:44, John D. Hume wrote:
> Assume a queue is your only state and `add` and `clear` are your private
> fns that take a queue as first argument.
> 
> (defn new-scheduler []
>   (let [queue (...)]
>     {:add (partial add queue)
>      :clear (partial clear queue)}))
> 
> There are several disadvantages to this, however. The biggest in my book
> is that it achieves your goal, and you're limited in the same way your
> users are. You can't add behavior to an already created scheduler
> (unless it's built on adding and clearing). Furthermore, if you
> dynamically recompile `add` or `clear`, it won't change the behavior of
> an already created scheduler, since partial has the fns, not the symbols
> or vars that point at them. (These same disadvantages apply to a reified
> protocol.)

You can make dynamic recompilation work by referring to the vars and not
the functions:

    {:add (partial #'add queue)
     :clear (partial #'clear queue)}

This works because vars implement `IFn` by delegating to the function
they contain.

-- 
Timo

-- 
-- 
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/groups/opt_out.


Reply via email to