From ddbb9971fd0171bee92f773abec89bf74d90335f Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Tue, 8 Feb 2011 07:51:41 -0600 Subject: [PATCH] Move r-infix blanks to the macro itself. --- src/koans/macros.clj | 8 ++++---- src/path_to_answer_sheet.clj | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/koans/macros.clj b/src/koans/macros.clj index 709fbac..5843900 100644 --- a/src/koans/macros.clj +++ b/src/koans/macros.clj @@ -5,19 +5,19 @@ (list (second form) (first form) (nth form 2))) (defmacro infix-better [form] - `(~(second form) + `(~(second form) ; Note the syntax-quote (`) and unquote (~) characters! __ __ )) (defmacro r-infix [form] (cond (not (seq? form)) - form + __ (= 1 (count form)) `(r-infix ~(first form)) :else (let [operator (second form) first-arg (first form) - others (drop 2 form)] + others __] `(~operator (r-infix ~first-arg) (r-infix ~others))))) @@ -40,5 +40,5 @@ (= __ (macroexpand '(infix-better ( 10 + (2 * 3))))) "Really, you dont understand recursion until you understand recursion" - (= __ (r-infix (10 + (2 * 3) + (4 * 5))))) + (= 36 (r-infix (10 + (2 * 3) + (4 * 5))))) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 80f3dc5..5b2e8f6 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -136,12 +136,13 @@ "macros" {"__" ['~(first form) '~(nth form 2) + 'form + '(drop 2 form) "Hello, Macros!" 10 ''(+ 9 1) ''(* 10 2) - ''(+ 10 (2 * 3)) - 36]} + ''(+ 10 (2 * 3))]} }) (defn replace-with [s k replacements]