From fb3f05e2c6f3dd6af002340145c747855a007210 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Fri, 8 Jul 2011 15:57:44 -0500 Subject: [PATCH] Add first cut at Java interop --- src/koans/java_interop.clj | 16 ++++++++++++++++ src/path_to_answer_sheet.clj | 13 ++++++++++++- src/runner/koans.clj | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/koans/java_interop.clj diff --git a/src/koans/java_interop.clj b/src/koans/java_interop.clj new file mode 100644 index 0000000..2a86d08 --- /dev/null +++ b/src/koans/java_interop.clj @@ -0,0 +1,16 @@ +(meditations + "You may have done more with Java than you know" + (= __ (class "warfare")) ; hint: try typing (javadoc "warfare") in the REPL + + "The dot signifies easy and direct Java interoperation" + (= __ (.toUpperCase "select * from")) + + "But instance method calls are very different from normal functions" + (= ["SELECT" "FROM" "WHERE"] (map ___ ["select" "from" "where"])) + + "Constructing might be harder than breaking" + (= 10 (let [latch (java.util.concurrent.CountDownLatch. __)] + (.getCount latch))) + + "Static methods are slashing prices!" + (== __ (Math/pow 2 10))) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index b234faf..3509c64 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -192,7 +192,18 @@ nil [true false] (str "Congratulations on your Best Picture Oscar, " - "Evil Alien Conquerors!")]}}) + "Evil Alien Conquerors!")]} + + "java_interop" {"__" ['java.lang.String + "SELECT * FROM" + 10 + 1024 + ] + "___" ['#(.toUpperCase %) + ] + } + + }) (defn replace-with [s k replacements] (let [unreplaced-texts (split s (re-pattern (str "\\b" k "\\b")))] diff --git a/src/runner/koans.clj b/src/runner/koans.clj index 9e2de67..fcbdaf8 100644 --- a/src/runner/koans.clj +++ b/src/runner/koans.clj @@ -19,7 +19,8 @@ "refs" "atoms" "macros" - "datatypes"]) + "datatypes" + "java_interop"]) (defn ordered-koan-paths [] (map (fn [koan-name]