File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
* Added a compile-time warning for attempting to call a function with an unsupported number of arguments (#671 )
11
11
12
12
### Changed
13
- * Cause exceptions arising from compilation issues during macroexpansion will no longer be nested for each level of macroexpansion (#852 )
13
+ * Cause exceptions arising from compilation issues during macroexpansion will no longer be nested for each level of macroexpansion (#852 )
14
+ * Support for optional metadata argument in ` defmulti ` (#857 )
14
15
15
16
### Fixed
16
17
* Fix a bug where ` basilisp.lang.compiler.exception.CompilerException ` would nearly always suppress line information in it's ` data ` map (#845 )
Original file line number Diff line number Diff line change 5247
5247
;;;;;;;;;;;;;;;;;;
5248
5248
5249
5249
(defmacro defmulti
5250
- "Define a new multimethod with the given dispatch function.
5250
+ "Define a new multimethod with the given ``name`` and a ``body`` consisting of an
5251
+ optional docstring, optional metadata map, a dispatch function and options of key/value
5252
+ pairs.
5251
5253
5252
5254
Multimethod dispatch functions should be defined with the same arity or arities as
5253
5255
the registered methods. The provided dispatch function will be called first on all
5286
5288
[name & body]
5287
5289
(let [doc (when (string? (first body))
5288
5290
(first body))
5289
- name (if doc
5290
- (vary-meta name assoc :doc doc)
5291
- name)
5292
5291
body (if doc
5293
5292
(rest body)
5294
5293
body)
5294
+ mt (when (map? (first body))
5295
+ (first body))
5296
+ body (if mt
5297
+ (rest body)
5298
+ body)
5299
+ name (vary-meta name merge mt)
5300
+ name (if doc
5301
+ (vary-meta name assoc :doc doc)
5302
+ name)
5295
5303
dispatch-fn (first body)
5296
5304
opts (apply hash-map (rest body))]
5297
5305
`(def ~name (basilisp.lang.multifn/MultiFunction (quote ~name)
Original file line number Diff line number Diff line change 93
93
(testing "cannot establish conflicting preference"
94
94
(is (thrown? basilisp.lang.runtime/RuntimeException)
95
95
(prefer-method os-lineage :os/bsd :os/unix)))))
96
+
97
+ (defmulti args-test1 "test1" :x)
98
+ (defmulti args-test2 {:test 2} :x)
99
+ (defmulti args-test3 "test3" {:test 3} :x)
100
+ (defmulti args-test4 "test4" {:doc "other"} :x)
101
+
102
+ (deftest multi-args-optional-test
103
+ (let [mt1 (meta #'args-test1)
104
+ mt2 (meta #'args-test2)
105
+ mt3 (meta #'args-test3)
106
+ mt4 (meta #'args-test4)]
107
+ (is (= "test1" (:doc mt1)))
108
+ (is (= 2 (:test mt2)))
109
+ (is (= {:doc "test3" :test 3} (select-keys mt3 [:doc :test])))
110
+ (is (= "test4" (:doc mt4)))))
You can’t perform that action at this time.
0 commit comments