From 63ba3f3d59f84a9857ec8ea28d18334d67eb5791 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Tue, 9 Feb 2010 12:57:08 +0800 Subject: [PATCH] adding about functions --- koans/about_functions.clj | 21 +++++++++++++++++++++ koans/path_to_enlightenment.clj | 1 + 2 files changed, 22 insertions(+) create mode 100644 koans/about_functions.clj diff --git a/koans/about_functions.clj b/koans/about_functions.clj new file mode 100644 index 0000000..0c5aac3 --- /dev/null +++ b/koans/about_functions.clj @@ -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] (__ __ __))))) diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index e0934f7..745524a 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -16,4 +16,5 @@ (load "about_vectors") (load "about_sets") (load "about_maps") +(load "about_functions") (println "You have acheived clojure enlightenment. Namaste.")