On Jan 5, 4:56 pm, Meikel Brandmeyer <m...@kotka.de> wrote:
> Dear Clojurians,
>
> This patch allows multimethods to use different hierarchies, than
> the global hierarchy for use with isa?. Currently only the global
> hierarchy is possible.
>
> The patch extends the MultiFn class to accept also a Var pointing
> to a hierarchy. The rationale is, that otherwise the multimethod
> cannot be extended with derivation after it's definition. Hence
> it cannot receive the hierarchy directly.
>
> To promote that every hierarchy must be a Var, derive and underive
> are modified to act on vars instead of the hierarchies directly.
> Furthermore the convenience macros defhierarchy and defhierarchy-
> are provided, which define new hierarchies with optional docstring
> support and automatic initialisation with make-hierarchy.
>
> This is listed as a "hot" item in the Todo list and is connected
> tohttp://code.google.com/p/clojure/issues/detail?id=8.
> In fact the patch there is needed as a prerequisite.
>
> Example of usage:
>
> (defhierarchy our-hierarchy
> "This is a dedicated hierarchy for our own purposes!")
>
> ; Note: here we need the Var, hence the #'.
> ; Should this be handled via a macro?
> (derive #'our-hierarchy :xxx :yyy)
>
> (defmulti foo identity :hierarchy our-hierarchy)
>
> (defmethod foo :yyy
> [x]
> (println "We are in" :yyy "but got" x))
>
> Comments and feedback appreciated.
>
Thanks Meikel. I have a couple of points:
First, making derive and underive act on vars instead of the
hierarchies directly is not good - it reduces the generality
needlessly. Good practice is to make pure fns, then do the reference
part, not mix the two.
Second, there's no reason to bind MultiFn to Var - any IRef will do.
Then people can put their hierarchies in Atoms/Refs or whatever.
Third, I don't see the need for defhierarchy at this point.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---