From b55332f4a8fb405db30c57927156b8784921b011 Mon Sep 17 00:00:00 2001 From: Micah Date: Tue, 16 Nov 2010 22:23:33 -0600 Subject: [PATCH] added to the creating-fuctions sheet --- script/run.clj | 4 ++++ script/test.clj | 4 ++++ src/koans/creating_functions.clj | 36 ++++++++++++++++++++++++++++++++ src/koans/partial_functions.clj | 9 -------- src/path_to_answer_sheet.clj | 11 +++++++--- src/path_to_enlightenment.clj | 2 +- 6 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 script/run.clj create mode 100644 script/test.clj create mode 100644 src/koans/creating_functions.clj delete mode 100644 src/koans/partial_functions.clj diff --git a/script/run.clj b/script/run.clj new file mode 100644 index 0000000..65f1f84 --- /dev/null +++ b/script/run.clj @@ -0,0 +1,4 @@ +(load "path_to_enlightenment") +(do + (in-ns 'path-to-enlightenment) + (run)) \ No newline at end of file diff --git a/script/test.clj b/script/test.clj new file mode 100644 index 0000000..1e4fbfa --- /dev/null +++ b/script/test.clj @@ -0,0 +1,4 @@ +(load "path_to_answer_sheet") +(do + (in-ns 'path-to-answer-sheet) + (run)) \ No newline at end of file diff --git a/src/koans/creating_functions.clj b/src/koans/creating_functions.clj new file mode 100644 index 0000000..926c0d9 --- /dev/null +++ b/src/koans/creating_functions.clj @@ -0,0 +1,36 @@ +(defn square [x] (* x x)) + +(meditations + + "One may know what they seek by knowing what they do not seek" + (= [__ __ __] (let [not-a-symbol? (complement symbol?)] + (map not-a-symbol? [:a 'b "c"]))) + + "Praise and 'complement' may help you separate the wheat from the chaff" + (= [:wheat "wheat" 'wheat] + (let [not-nil? ___] + (filter not-nil? [nil :wheat nil "wheat" nil 'wheat nil]))) + + "Partial functions allow procrastination" + (= 20 (let [multiply-by-5 (partial * 5)] + (___ __))) + + "Don't forget: first things first" + (= [__ __ __ __] + (let [ab-adder (partial concat [:a :b])] + (ab-adder [__ __]))) + + "Functions can joins forces as one 'composed' function" + (= 25 (let [inc-and-square (comp square inc)] + (inc-and-square __))) + + "Have a go on a tripple dec-er" + (= __ (let [double-dec (comp dec dec)] + (double-dec 10))) + + "Becareful the order in which you mix your functions" + (= 99 (let [square-and-dec ___] + (square-and-dec 10))) + ) + + diff --git a/src/koans/partial_functions.clj b/src/koans/partial_functions.clj deleted file mode 100644 index a30238b..0000000 --- a/src/koans/partial_functions.clj +++ /dev/null @@ -1,9 +0,0 @@ -(meditations - "Partial functions allow procrastination" - (= 20 (let [multiply-by-5 (partial * 5)] - (___ __))) - - "Don't forget: first things first" - (= [__ __ __ __] - (let [ab-adder (partial concat [:a :b])] - (ab-adder [__ __])))) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 4027ee0..933b27c 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -86,10 +86,15 @@ '(odd? index) '(* index index) '[row column] ]} - "partial_functions" {"__" [4 + "creating_functions" {"__" [true false true + 4 :a :b :c :d - :c :d] - "___" ["multiply-by-5"]} + :c :d + 4 + 8] + "___" ['(complement nil?) + "multiply-by-5" + '(comp dec square)]} "recursion" {"__" [true 'acc '(loop [n n acc 1] (if (zero? n) diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index 0475659..a3051bb 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -25,7 +25,7 @@ "higher_order_functions" "runtime_polymorphism" "sequence_comprehensions" - "partial_functions" + "creating_functions" "recursion" "destructuring" "refs"])