Multimedia is created using defmulti ; you are doing it right. defmulti requires a name and a submit function (and a docstring, as well as some parameters if you want, but forget about it).
(defmulti random-val identity)
When you implement a multimethod using defmethod , you need to specify the name of the multimethod you are using, the send value that it should match, and then the tail of the function (arglist plus whatever you want).
(defmethod random-val :trans [t] (random-trans)) (defmethod random-val :amt [t] (random-amt))
You get java.lang.IllegalArgumentException: No method in multimethod 'random-val' for dispatch value: null (NO_SOURCE_FILE:0) , because when the send function you assigned random-val :val-type applies to any other keyword, it gives you null . When Clojure tries to find a method that matches this send value, it fails.
But even if this does not happen, your specific methods have 0 arity (do not take values), so you also need to fix it (done above).
Lastly, this is not like using protocols. Just use two different functions: random-amount and random-trans .
Note that the Clojure website has good multi-point explanations.
Isaac source share