I am trying to define a multimethod and its implementation in a separate file. It goes something like this: In file 1
(ns thing.a.b)
(defn dispatch-fn [x] x)
(defmulti foo dispatch-fn)
In file 2
(ns thing.a.b.c
(:require [thing.a.b :refer [foo]])
(defmethod foo "hello" [s] s)
(defmethod foo "goodbye" [s] "TATA")
And in the main file when I am calling the method I define something like this:
(ns thing.a.e
(:require thing.a.b :as test))
.
.
.
(test/foo "hello")
When I do this I get an exception saying "No method in multimethod 'foo'for dispatch value: hello
What am I doing wrong? Or is it not possible to define implementations of multimethods in separate files?
It is possible. The problem is because thing.a.b.c
namespace isn't loaded. You have to load it before using.
This is a correct example:
(ns thing.a.e
(:require
[thing.a.b.c] ; Here all your defmethods loaded
[thing.a.b :as test]))
(test/foo "hello")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With