From 6b82a3fc56942bd5934eafd1581ec69ccb692650 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 10 May 2012 23:02:08 +0100 Subject: [PATCH] CLJ-835 Refine doc string for defmulti :hierarchy option --- src/clj/clojure/core.clj | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index afeb3b1..3ef4b75 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1570,9 +1570,32 @@ The docstring and attribute-map are optional. Options are key-value pairs and may be one of: - :default the default dispatch value, defaults to :default - :hierarchy the isa? hierarchy to use for dispatching - defaults to the global hierarchy" + + :default + + The default dispatch value, defaults to :default + + :hierarchy + + The isa? hierarchy value used for dispatch, e.g. + (isa? my-hierarchy ::square ::shape) + + Hierarchies are type-like relationships that do not depend upon type + inheritance. The hierarchy relationship can be established via derive, + and the root ancestor may be obtained from make-hierarchy in order to + avoid directly using the global hierarchy map. Multimethods expect the + value of the hierarchy option to be supplied as a reference type e.g. + a var. You can supply this option via the Var-quote dispatch macro (#'). + If no hierarchy is supplied, defaults to the global hierarchy. + + Hierarchy example: + + (def my-hierarchy (-> (make-hierarchy) + (derive ::rect ::shape) + (derive ::square ::rect) + (derive ::circle ::shape))) + + (defmulti foo identity :hierarchy #'my-hierarchy)" {:arglists '([name docstring? attr-map? dispatch-fn & options]) :added "1.0"} [mm-name & options] -- 1.7.8.3