2
我希望能够采取多种方法,将其作为独立变量克隆并添加到它,而无需更改原始内容。如何才能做到这一点?是否可以克隆multimethod?
(defmulti hello :type)
(defmethod hello :a
[e] (assoc e :a 1))
(hello {:type :a})
=> {:type :a :a 1}
;; my attempt at cloning
(def world @#'hello)
(defmethod world :b
[e] (assoc e :b 2))
(world {:type :b})
=> {:type :b :b 2}
;; I want this to throw... but because `hello` and `world`
;; are the same function, it still works
(hello {:type :b})
=> {:type :b :b 2}