adding about functions

This commit is contained in:
Colin Jones 2010-02-09 12:57:08 +08:00 committed by Relevance, Inc.
parent 012d86b382
commit 63ba3f3d59
2 changed files with 22 additions and 0 deletions

21
koans/about_functions.clj Normal file
View File

@ -0,0 +1,21 @@
(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] (__ __ __)))))

View File

@ -16,4 +16,5 @@
(load "about_vectors") (load "about_vectors")
(load "about_sets") (load "about_sets")
(load "about_maps") (load "about_maps")
(load "about_functions")
(println "You have acheived clojure enlightenment. Namaste.") (println "You have acheived clojure enlightenment. Namaste.")