From af19d14c4050bb59d8a7cc7a62de732ab87e19c2 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Mon, 8 Nov 2010 18:07:59 -0600 Subject: [PATCH] Finish off vector destructuring features. --- src/koans/destructuring.clj | 15 ++++++++++++++- src/path_to_answer_sheet.clj | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/koans/destructuring.clj b/src/koans/destructuring.clj index b5a7957..9516305 100644 --- a/src/koans/destructuring.clj +++ b/src/koans/destructuring.clj @@ -4,8 +4,21 @@ [:foo :bar])) "Whether in function definitions" - (= "First comes love, then comes marriage, then comes Clojure with the baby carriage" + (= (str "First comes love, " + "then comes marriage, " + "then comes Clojure with the baby carriage") ((fn [[a b c]] __) ["love" "marriage" "Clojure"])) + "Or in let expressions" + (= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah" + (let [[first-name last-name & aliases] + (list "Rich" "Hickey" "The Clojurer" "Go Time" "Macro Killah")] + __)) + + "You can regain the full argument if you like arguing" + (= {:original-parts ["Steven" "Hawking"] :named-parts {:first "Steven" :last "Hawking"}} + (let [[first-name last-name :as full-name] ["Steven" "Hawking"]] + __)) + ) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index d7e49f2..6bdb9dd 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -1,6 +1,6 @@ (ns path-to-answer-sheet (:use [path-to-enlightenment :exclude (run)] - [clojure.string :only (join split)])) + [clojure.string :only (join split trim)])) (def answers {"equalities" {"__" [true @@ -97,7 +97,20 @@ (recur (dec n) (* acc n))))] "___" ['not]} "destructuring" {"__" ["\":bar:foo\"" - '(format "First comes %s, then comes %s, then comes %s with the baby carriage" a b c) ]} + '(format (str "First comes %s, " + "then comes %s, " + "then comes %s with the baby carriage") + a b c) + '(trim + (apply str + (interleave + (apply list + first-name + last-name + (interleave (repeat "aka") aliases)) + (repeat " ")))) + '{:original-parts full-name + :named-parts {:first first-name :last last-name}} ]} }) (defn replace-with [s k replacements]