From bd5f7eadd7968eb60dcf3630bcaac5a68a7c766e Mon Sep 17 00:00:00 2001 From: Manas Karekar Date: Sun, 3 Mar 2013 16:33:39 -0500 Subject: [PATCH] Exercise 9 - runtime polymorphism --- src/koans/09_runtime_polymorphism.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/koans/09_runtime_polymorphism.clj b/src/koans/09_runtime_polymorphism.clj index a8171ee..37816e7 100644 --- a/src/koans/09_runtime_polymorphism.clj +++ b/src/koans/09_runtime_polymorphism.clj @@ -7,19 +7,19 @@ "!"))) (defmulti diet (fn [x] (:eater x))) -(defmethod diet :herbivore [a] __) -(defmethod diet :carnivore [a] __) -(defmethod diet :default [a] __) +(defmethod diet :herbivore [a] (str (:name a) " eats veggies.")) +(defmethod diet :carnivore [a] (str (a :name) " eats animals.")) +(defmethod diet :default [a] (str "I don't know what " (:name a) " eats.")) (meditations "Some functions can be used in different ways - with no arguments" - (= __ (hello)) + (= "Hello World!" (hello)) "With one argument" - (= __ (hello "world")) + (= "Hello, you silly world." (hello "world")) "Or with many arguments" - (= __ + (= "Hello to this group: Peter, Paul, Mary!" (hello "Peter" "Paul" "Mary")) "Multimethods allow more complex dispatching"