Merge pull request #10 from HantonSacu/HantonSacu-10

Solve runtime polymorphism
This commit is contained in:
Kenneth Kostrešević 2021-12-16 16:08:16 +01:00 committed by GitHub
commit 3153ecce3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"