2014-01-26 00:04:22 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Some functions can be used in different ways - with no arguments"
|
2010-02-14 00:19:13 +00:00
|
|
|
(= __ (hello))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "With one argument"
|
2010-02-14 00:19:13 +00:00
|
|
|
(= __ (hello "world"))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Or with many arguments"
|
2010-02-14 00:19:13 +00:00
|
|
|
(= __
|
|
|
|
|
(hello "Peter" "Paul" "Mary"))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Multimethods allow more complex dispatching"
|
2010-02-14 00:19:13 +00:00
|
|
|
(= "Bambi eats veggies."
|
|
|
|
|
(diet {:species "deer" :name "Bambi" :age 1 :eater :herbivore}))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Animals have different names"
|
2013-10-26 17:00:21 +00:00
|
|
|
(= "Thumper eats veggies."
|
2015-07-19 22:41:27 +00:00
|
|
|
(diet {:species "rabbit" :name "Thumper" :age 1 :eater :herbivore}))
|
2013-10-26 17:00:21 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Different methods are used depending on the dispatch function result"
|
2014-01-21 13:14:00 +00:00
|
|
|
(= "Simba eats animals."
|
|
|
|
|
(diet {:species "lion" :name "Simba" :age 1 :eater :carnivore}))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "You may use a default method when no others match"
|
2010-02-14 00:19:13 +00:00
|
|
|
(= "I don't know what Rich Hickey eats."
|
2016-02-27 02:33:05 +00:00
|
|
|
(diet {:name "Rich Hickey"}))
|