From 72ee00960c1c9f02bc4a5ee62a166041736003ce Mon Sep 17 00:00:00 2001 From: Kenneth Kostresevic Date: Wed, 15 Dec 2021 14:58:49 +0100 Subject: [PATCH] Solve runtime polymorphism --- src/koans/10_runtime_polymorphism.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/koans/10_runtime_polymorphism.clj b/src/koans/10_runtime_polymorphism.clj index 8be1c6a..256daeb 100644 --- a/src/koans/10_runtime_polymorphism.clj +++ b/src/koans/10_runtime_polymorphism.clj @@ -10,19 +10,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 (:name a), " 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"