UP | HOME

Clojure Multimethods can be overriden at runtime.
클로저 Multimethods는 런타임에 재정의 될 수 있습니다.

I have supposed Multimethods is immutable(or fixed at compile time), However, I realized it was not true.
Multimethods is an instance of class that inherit the AFn class.

You can test it as following:

(ns example.mm)
(defmulti mm :type)
(defmethod mm :a [m] (println m))
(defmethod mm :b [m] (println m))
(ns example.core
  (:gen-class)
  (:require example.mm))
(def mm example.mm/mm)
(defmethod mm :a [m] (println "new:" m))
(defn -main [& _]
  (example.mm/mm {:type :a})
  (example.mm/mm {:type :b}))

<2017-06-12 Mon>: Update.