diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/core.clj | 5 | ||||
-rw-r--r-- | src/jvm/clojure/lang/MultiFn.java | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index f44fcb71..934dbe89 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1085,6 +1085,11 @@ "Given a multimethod, returns a map of dispatch values -> dispatch fns" [#^clojure.lang.MultiFn multifn] (.getMethodTable multifn)) +(defn get-method + "Given a multimethod and a dispatch value, returns the dispatch fn + that would apply to that value, or nil if none apply and no default" + [#^clojure.lang.MultiFn multifn dispatch-val] (.getMethod multifn dispatch-val)) + (defn prefers "Given a multimethod, returns a map of preferred value -> set of other values" [#^clojure.lang.MultiFn multifn] (.getPreferTable multifn)) diff --git a/src/jvm/clojure/lang/MultiFn.java b/src/jvm/clojure/lang/MultiFn.java index d7b089ce..1efa84b6 100644 --- a/src/jvm/clojure/lang/MultiFn.java +++ b/src/jvm/clojure/lang/MultiFn.java @@ -93,7 +93,7 @@ private IPersistentMap resetCache() throws Exception{ return methodCache; } -synchronized private IFn getFn(Object dispatchVal) throws Exception{ +synchronized public IFn getMethod(Object dispatchVal) throws Exception{ if(cachedHierarchy != hierarchy.deref()) resetCache(); IFn targetFn = (IFn) methodCache.valAt(dispatchVal); @@ -103,6 +103,11 @@ synchronized private IFn getFn(Object dispatchVal) throws Exception{ if(targetFn != null) return targetFn; targetFn = (IFn) getMethodTable().valAt(defaultDispatchVal); + return targetFn; +} + +private IFn getFn(Object dispatchVal) throws Exception{ + IFn targetFn = getMethod(dispatchVal); if(targetFn == null) throw new IllegalArgumentException(String.format("No method for dispatch value: %s", dispatchVal)); return targetFn; |