The defmulti
form will create a multifunction that returns a value, which is then used to determine which body of code to evaluate in the defmethod
form. The first argument of the defmulti
form is the symbol that holds the multimethod. The second argument is a function, and the number of arguments this function has will also be required by the defmethod
forms.
The following example will make a decision on the return vector that's based on the customer
and bottle
arguments. The vector will look similar to [:sweet :carbon true true]
.
user> (defmulti customer-drinks (fn [customer bottle] [(if (:sweet? bottle) :sweet :not-sweet) (if (:carbonated? bottle) :carbon :no-carbon) (:drinks-sweet? customer) (:drinks-carbonated? customer)])) ...
No credit card required