clojure-koans/src/koans/about_functions.clj

22 lines
495 B
Clojure
Raw Normal View History

2010-02-09 04:57:08 +00:00
(defn count-items [& items]
(count items))
(meditations
"Functions are often defined before they are used"
(= __ (count-items :a :b :c :d))
"But they can also be defined inline"
(= __ ((fn [n] (Math/pow n 10)) 2))
"Or using even shorter syntax"
(= __ (#(Math/pow % 10)))
"Functions can beget others"
(= __ (((fn []
(fn [a b] (+ a b))))
4 5))
"Higher-order functions take function arguments"
(= 25 ((fn [f] (f 5))
(fn [n] (__ __ __)))))