diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-02-10 01:05:10 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-02-10 01:05:10 +0000 |
commit | 2c0b7f60cbbc26b9efbf1a687b86d18bb39003a2 (patch) | |
tree | 6ce5df5c8a6a3af8085fead97a4c8a8c00a41bc4 /src/clj | |
parent | 4339c80e5d70113b26c4d2dbfaa2a9ed3689916d (diff) |
added per-defmulti hierarchies, patch from mb
Diffstat (limited to 'src/clj')
-rw-r--r-- | src/clj/clojure/core.clj | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index b5592c54..a56a503e 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1011,12 +1011,16 @@ ([x form & more] `(-> (-> ~x ~form) ~@more))) ;;multimethods +(def global-hierarchy) + (defmacro defmulti "Creates a new multimethod with the associated dispatch function. 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" + :default the default dispatch value, defaults to :default + :hierarchy the isa? hierarchy to use for dispatching + defaults to the global hierarchy" {:arglists '([name docstring? attr-map? dispatch-fn & options])} [mm-name & options] (let [docstring (if (string? (first options)) @@ -1042,10 +1046,11 @@ m)] (when (= (count options) 1) (throw (Exception. "The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)"))) - (let [options (apply hash-map options) - default (get options :default :default)] + (let [options (apply hash-map options) + default (get options :default :default) + hierarchy (get options :hierarchy #'global-hierarchy)] `(def ~(with-meta mm-name m) - (new clojure.lang.MultiFn ~dispatch-fn ~default))))) + (new clojure.lang.MultiFn ~dispatch-fn ~default ~hierarchy))))) (defmacro defmethod "Creates and installs a new method of multimethod associated with dispatch-value. " |