Skip to content

Commit 82901e8

Browse files
committed
allow defmulti to be called without ctx
1 parent ba34e57 commit 82901e8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/sci/impl/multimethods.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(:refer-clojure :exclude [defmulti defmethod])
44
(:require
55
#?(:clj [clojure.string :as str])
6+
[sci.ctx-store :as store]
67
[sci.impl.hierarchies :refer [global-hierarchy]]))
78

89
#?(:clj (set! *warn-on-reflection* true))
@@ -44,7 +45,10 @@
4445
or the var special form)."
4546
{:arglists '([name docstring? attr-map? dispatch-fn & options])}
4647
[_ _ ctx mm-name & options]
47-
(let [docstring (if (string? (first options))
48+
(let [[ctx mm-name options] (if (symbol? ctx)
49+
[nil ctx mm-name options]
50+
[ctx mm-name options])
51+
docstring (if (string? (first options))
4852
(first options)
4953
nil)
5054
options (if (string? (first options))
@@ -71,7 +75,7 @@
7175

7276
(let [options (apply hash-map options)
7377
default (get options :default :default)
74-
hierarchy (get options :hierarchy (global-hierarchy ctx))]
78+
hierarchy (get options :hierarchy (global-hierarchy (or ctx (store/get-ctx))))]
7579
(check-valid-options options :default :hierarchy)
7680
#?(:clj `(let [v# (def ~mm-name)]
7781
(when-not (and (clojure.core/has-root-impl v#) (clojure.core/multi-fn?-impl (deref v#)))

0 commit comments

Comments
 (0)