0
I created a clojure project to validate defmulti Feature with defmethod implementations in other namespace. However, when running the defmulti Dispatcher project it does not locate the correct implementation.
Implementation
(ns multi-metodos.executar)
(defmulti run :tipo)
(ns multi-metodos.sms
(:require [multi-metodos.executar :as exe]))
(defmethod exe/run :default [_]
(println "default"))
(ns multi-metodos.notificacao
(:require [multi-metodos.executar :as exe]))
(defmethod exe/run :notificacao [_]
(println "Enviando notificacao"))
(ns multi-metodos.email
(:require [multi-metodos.executar :as exe]))
(defmethod exe/run :email [_]
(println "Enviando email"))
(ns multi-metodos.core
(:require [multi-metodos.executar :as exe]))
(defn -main []
(println "Ola")
(exe/run {:tipo :email}))
error generated:
Exception in thread "main" Syntax error compiling at (C:\Users\guilherme.angelico\AppData\Local\Temp\form-init7125751530945241762.clj:1:121).
at clojure.lang.Compiler.load(Compiler.java:7647)
at clojure.lang.Compiler.loadFile(Compiler.java:7573)
at clojure.main$load_script.invokeStatic(main.clj:452)
at clojure.main$init_opt.invokeStatic(main.clj:454)
at clojure.main$init_opt.invoke(main.clj:454)
at clojure.main$initialize.invokeStatic(main.clj:485)
at clojure.main$null_opt.invokeStatic(main.clj:519)
at clojure.main$null_opt.invoke(main.clj:516)
at clojure.main$main.invokeStatic(main.clj:598)
at clojure.main$main.doInvoke(main.clj:561)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No method in multimethod 'run' for dispatch value: :email
at clojure.lang.MultiFn.getFn(MultiFn.java:156)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at multi_metodos.core$_main.invokeStatic(core.clj:6)
at multi_metodos.core$_main.invoke(core.clj:4)
at clojure.lang.Var.invoke(Var.java:380)
at user$eval140.invokeStatic(form-init7125751530945241762.clj:1)
at user$eval140.invoke(form-init7125751530945241762.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:7176)
at clojure.lang.Compiler.eval(Compiler.java:7166)
at clojure.lang.Compiler.load(Compiler.java:7635)
... 12 more