diff --git a/.gitignore b/.gitignore index cbbcfd7..733fa44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,203 @@ *~ bin -classes -lib releases -target *.jar + +# Created by https://www.gitignore.io/api/clojure,osx,linux,windows,leiningen,intellij,eclipse,sublimetext + +### Clojure ### +pom.xml +pom.xml.asc +*jar +/lib/ +/classes/ +/target/ +/checkouts/ +.lein-deps-sum +.lein-repl-history +.lein-plugins/ +.lein-failures +.nrepl-port + + +### OSX ### .DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Linux ### +*~ + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### Leiningen ### +pom.xml +pom.xml.asc +*jar +/lib/ +/classes/ +/target/ +/checkouts/ .lein-deps-sum -.lein-plugins .lein-repl-history +.lein-plugins/ +.lein-failures +.nrepl-port + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + +### Eclipse ### +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse + + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + diff --git a/ideaboard.txt b/ideaboard.txt index d72c7cc..46e5979 100644 --- a/ideaboard.txt +++ b/ideaboard.txt @@ -3,7 +3,6 @@ Concepts / Language Features Quoting -strings & character literals new record syntax Agents Vars @@ -27,4 +26,3 @@ map-indexed partition-all partition-by repeatedly - diff --git a/project.clj b/project.clj index b208d9f..9aca071 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ (defproject clojure-koans "0.5.1-SNAPSHOT" :description "The Clojure koans." - :dependencies [[org.clojure/clojure "1.5.1"] + :dependencies [[org.clojure/clojure "1.7.0"] [koan-engine "0.2.3"]] :dev-dependencies [[lein-koan "0.1.3"]] :profiles {:dev {:dependencies [[lein-koan "0.1.3"]]}} diff --git a/resources/koans.clj b/resources/koans.clj index 19dddc6..b73f9fc 100644 --- a/resources/koans.clj +++ b/resources/koans.clj @@ -10,7 +10,31 @@ "hello" 3]}] - ["02_lists" {"__" [1 2 3 4 5 + ["02_strings" {"__" ["hello" + "world" + "Cool " + "right?" + 0 + 11 + false + 6 11 + "123" + ", " + "1" "2" "3" + "olleh" + "hello" + 13 + -1 + "hello world" + true + false + false + "a" + true + true + false]}] + + ["03_lists" {"__" [1 2 3 4 5 1 [2 3 4 5] 3 @@ -23,7 +47,7 @@ "No dice!" ()]}] - ["03_vectors" {"__" [1 + ["04_vectors" {"__" [1 [1] [nil nil] 2 @@ -34,14 +58,14 @@ [:butter :and] 3]}] - ["04_sets" {"__" [[3] + ["05_sets" {"__" [[3] 3 #{1 2 3 4 5} #{1 2 3 4 5} #{2 3} #{1 4}]}] - ["05_maps" {"__" [:b 2 + ["06_maps" {"__" [:b 2 1 2 2 @@ -57,7 +81,7 @@ 2010 2014 2018 "PyeongChang" "Sochi" "Vancouver"]}] - ["06_functions" {"__" [81 + ["07_functions" {"__" [81 20 10 60 @@ -68,7 +92,7 @@ (fn [f] (f 5)) (fn [f] (f 5))]}] - ["07_conditionals" {"__" [:a + ["08_conditionals" {"__" [:a [] nil :glory @@ -77,7 +101,7 @@ :bicycling "is that even exercise?"]}] - ["08_higher_order_functions" {"__" [4 8 12 + ["09_higher_order_functions" {"__" [4 8 12 (* x x) [false false true false false] () @@ -88,14 +112,14 @@ 100 (count a) (count b)]}] - ["09_runtime_polymorphism" {"__" [(str (:name a) " eats veggies.") + ["10_runtime_polymorphism" {"__" [(str (:name a) " eats veggies.") (str (:name a) " eats animals.") (str "I don't know what " (:name a) " eats.") "Hello World!" "Hello, you silly world." "Hello to this group: Peter, Paul, Mary!" ]}] - ["10_lazy_sequences" {"__" [[1 2 3 4] + ["11_lazy_sequences" {"__" [[1 2 3 4] [0 1 2 3 4] 10 95 @@ -103,14 +127,14 @@ :a] "___" [(fn [x] x)]}] - ["11_sequence_comprehensions" {"__" [[0 1 2 3 4 5] + ["12_sequence_comprehensions" {"__" [[0 1 2 3 4 5] (* x x) (range 10) (odd? x) (* x x) [row column] ]}] - ["12_creating_functions" {"__" [true false true + ["13_creating_functions" {"__" [true false true 4 :a :b :c :d :c :d @@ -120,7 +144,7 @@ multiply-by-5 (comp dec square)]}] - ["13_recursion" {"__" [true + ["14_recursion" {"__" [true acc (loop [coll coll acc ()] @@ -134,7 +158,7 @@ (recur (dec n) (* acc n))))] "___" [not]}] - ["14_destructuring" {"__" [":bar:foo" + ["15_destructuring" {"__" [":bar:foo" (format (str "An Oxford comma list of %s, " "%s, " "and %s.") @@ -156,7 +180,7 @@ street-address ", " city ", " state)) ]}] - ["15_refs" {"__" ["hello" + ["16_refs" {"__" ["hello" "hello" "better" "better!!!" @@ -165,7 +189,7 @@ ] "___" [(fn [x] (+ 20 x))]}] - ["16_atoms" {"__" [0 + ["17_atoms" {"__" [0 1 (swap! atomic-clock (partial + 4)) 20 @@ -173,7 +197,7 @@ atomic-clock 20 :fin ]}] - ["17_macros" {"__" [~(first form) + ["18_macros" {"__" [~(first form) ~(nth form 2) form (drop 2 form) @@ -183,7 +207,7 @@ '(* 10 2) '(+ 10 (2 * 3))]}] - ["18_datatypes" {"__" [(print + ["19_datatypes" {"__" [(print (str "You're really the " (.category this) ", " recipient "... sorry.")) @@ -195,7 +219,7 @@ (str "Congratulations on your Best Picture Oscar, " "Evil Alien Conquerors!")]}] - ["19_java_interop" {"__" [java.lang.String + ["20_java_interop" {"__" [java.lang.String "SELECT * FROM" 10 1024 @@ -203,14 +227,14 @@ "___" [#(.toUpperCase %) ] }] - ["20_partition" {"__" [partition + ["21_partition" {"__" [partition [:a :b :c] '((0 1 2) (3 4)) 5 :hello (6 :these :are) ]}] - ["21_group_by" {"__" [odd? + ["22_group_by" {"__" [odd? {5 ["hello" "world"] 3 ["foo" "bar"]} {1 [{:name "Bob" :id 1} {:last-name "Smith" :id 1}] @@ -219,7 +243,7 @@ {:naughty-list [{:name "Jimmy" :bad true} {:name "Joe" :bad true}] :nice-list [{:name "Jane" :bad false}]}]}] - ["22_meta" {"__" [{:league "National League"} + ["23_meta" {"__" [{:league "National League"} {:division "West"} "This doesn't implement the IObj interface" {:foo :bar} diff --git a/src/koans/02_strings.clj b/src/koans/02_strings.clj new file mode 100644 index 0000000..92f4817 --- /dev/null +++ b/src/koans/02_strings.clj @@ -0,0 +1,70 @@ +(ns koans.02-strings + (:require [koan-engine.core :refer :all] + [clojure.string :as string])) + +(meditations + "A string is nothing more than text surrounded by double quotes" + (= __ "hello") + + "But double quotes are just magic on top of something deeper" + (= __ (str 'world)) + + "You can do more than create strings, you can put them together" + (= "Cool right?" (str __ __)) + + "You can even get certain characters" + (= \C (get "Characters" __)) + + "Or even count the characters" + (= __ (count "Hello World")) + + "But strings and characters are not the same" + (= __ (= \c "c")) + + "What if you only wanted to get part of a string?" + (= "World" (subs "Hello World" __ __)) + + "How about joining together elements in a list?" + (= __ (string/join '(1 2 3))) + + "What if you wanted to separate them out?" + (= "1, 2, 3" (string/join __ '(1 2 3))) + + "Maybe you want to separate out all your lines" + (= [__ __ __] (string/split-lines "1\n2\n3")) + + "You may want to make sure your words are backwards" + (= __ (string/reverse "hello")) + + "Maybe you want to find the index of the first occurence of a substring" + (= 0 (.indexOf "hello world" __)) + + "Or maybe the last index of the same" + (= __ (.lastIndexOf "hello world, hello" "hello")) + + "But when something doesn't exist, it turns up negative" + (= __ (.indexOf "hello world" "bob")) + + "Sometimes you don't want whitespace cluttering the front and back" + (= __ (string/trim " \nhello world \t \n")) + + "You can check if something is a char" + (= __ (char? \c)) + + "But it may not be" + (= __ (char? "a")) + + "But chars aren't strings" + (= __ (string? \b)) + + "Strings are strings" + (= true (string? __)) + + "Some strings may be blank" + (= __ (string/blank? "")) + + "Even if at first glance they aren't" + (= __ (string/blank? " \n \t ")) + + "However, most strings aren't blank" + (= __ (string/blank? "hello?\nare you out there?"))) diff --git a/src/koans/02_lists.clj b/src/koans/03_lists.clj similarity index 98% rename from src/koans/02_lists.clj rename to src/koans/03_lists.clj index 8cdce7f..dbdf6f5 100644 --- a/src/koans/02_lists.clj +++ b/src/koans/03_lists.clj @@ -1,4 +1,4 @@ -(ns koans.02-lists +(ns koans.03-lists (:require [koan-engine.core :refer :all])) (meditations @@ -43,4 +43,3 @@ (rest '()) (catch IllegalStateException e "No dice!")))) - diff --git a/src/koans/03_vectors.clj b/src/koans/04_vectors.clj similarity index 97% rename from src/koans/03_vectors.clj rename to src/koans/04_vectors.clj index 87146d5..71970f6 100644 --- a/src/koans/03_vectors.clj +++ b/src/koans/04_vectors.clj @@ -1,4 +1,4 @@ -(ns koans.03-vectors +(ns koans.04-vectors (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/04_sets.clj b/src/koans/05_sets.clj similarity index 97% rename from src/koans/04_sets.clj rename to src/koans/05_sets.clj index d6b4063..a6e631f 100644 --- a/src/koans/04_sets.clj +++ b/src/koans/05_sets.clj @@ -1,4 +1,4 @@ -(ns koans.04-sets +(ns koans.05-sets (:require [koan-engine.core :refer :all] [clojure.set :as set])) diff --git a/src/koans/05_maps.clj b/src/koans/06_maps.clj similarity index 98% rename from src/koans/05_maps.clj rename to src/koans/06_maps.clj index 3fbaa34..3466864 100644 --- a/src/koans/05_maps.clj +++ b/src/koans/06_maps.clj @@ -1,4 +1,4 @@ -(ns koans.05-maps +(ns koans.06-maps (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/06_functions.clj b/src/koans/07_functions.clj similarity index 97% rename from src/koans/06_functions.clj rename to src/koans/07_functions.clj index fa3e9a1..4bf40a0 100644 --- a/src/koans/06_functions.clj +++ b/src/koans/07_functions.clj @@ -1,4 +1,4 @@ -(ns koans.06-functions +(ns koans.07-functions (:require [koan-engine.core :refer :all])) (defn multiply-by-ten [n] diff --git a/src/koans/07_conditionals.clj b/src/koans/08_conditionals.clj similarity index 97% rename from src/koans/07_conditionals.clj rename to src/koans/08_conditionals.clj index 764cd09..87b9fdf 100644 --- a/src/koans/07_conditionals.clj +++ b/src/koans/08_conditionals.clj @@ -1,4 +1,4 @@ -(ns koans.07-conditionals +(ns koans.08-conditionals (:require [koan-engine.core :refer :all])) (defn explain-exercise-velocity [exercise-term] diff --git a/src/koans/08_higher_order_functions.clj b/src/koans/09_higher_order_functions.clj similarity index 96% rename from src/koans/08_higher_order_functions.clj rename to src/koans/09_higher_order_functions.clj index 299022b..8b7fd3c 100644 --- a/src/koans/08_higher_order_functions.clj +++ b/src/koans/09_higher_order_functions.clj @@ -1,4 +1,4 @@ -(ns koans.08-higher-order-functions +(ns koans.09-higher-order-functions (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/09_runtime_polymorphism.clj b/src/koans/10_runtime_polymorphism.clj similarity index 97% rename from src/koans/09_runtime_polymorphism.clj rename to src/koans/10_runtime_polymorphism.clj index 3e3e76b..8be1c6a 100644 --- a/src/koans/09_runtime_polymorphism.clj +++ b/src/koans/10_runtime_polymorphism.clj @@ -1,4 +1,4 @@ -(ns koans.09-runtime-polymorphism +(ns koans.10-runtime-polymorphism (:require [koan-engine.core :refer :all])) (defn hello diff --git a/src/koans/10_lazy_sequences.clj b/src/koans/11_lazy_sequences.clj similarity index 96% rename from src/koans/10_lazy_sequences.clj rename to src/koans/11_lazy_sequences.clj index 061fab1..1023785 100644 --- a/src/koans/10_lazy_sequences.clj +++ b/src/koans/11_lazy_sequences.clj @@ -1,4 +1,4 @@ -(ns koans.10-lazy-sequences +(ns koans.11-lazy-sequences (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/11_sequence_comprehensions.clj b/src/koans/12_sequence_comprehensions.clj similarity index 96% rename from src/koans/11_sequence_comprehensions.clj rename to src/koans/12_sequence_comprehensions.clj index be8462e..f131e1a 100644 --- a/src/koans/11_sequence_comprehensions.clj +++ b/src/koans/12_sequence_comprehensions.clj @@ -1,4 +1,4 @@ -(ns koans.11-sequence-comprehensions +(ns koans.12-sequence-comprehensions (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/12_creating_functions.clj b/src/koans/13_creating_functions.clj similarity index 97% rename from src/koans/12_creating_functions.clj rename to src/koans/13_creating_functions.clj index 1ade8ae..7d84bc8 100644 --- a/src/koans/12_creating_functions.clj +++ b/src/koans/13_creating_functions.clj @@ -1,4 +1,4 @@ -(ns koans.12-creating-functions +(ns koans.13-creating-functions (:require [koan-engine.core :refer :all])) (defn square [x] (* x x)) diff --git a/src/koans/13_recursion.clj b/src/koans/14_recursion.clj similarity index 98% rename from src/koans/13_recursion.clj rename to src/koans/14_recursion.clj index 0bfcf6a..4c39666 100644 --- a/src/koans/13_recursion.clj +++ b/src/koans/14_recursion.clj @@ -1,4 +1,4 @@ -(ns koans.13-recursion +(ns koans.14-recursion (:require [koan-engine.core :refer :all])) (defn is-even? [n] diff --git a/src/koans/14_destructuring.clj b/src/koans/15_destructuring.clj similarity index 97% rename from src/koans/14_destructuring.clj rename to src/koans/15_destructuring.clj index de6a9ce..32fc983 100644 --- a/src/koans/14_destructuring.clj +++ b/src/koans/15_destructuring.clj @@ -1,4 +1,4 @@ -(ns koans.14-destructuring +(ns koans.15-destructuring (:require [koan-engine.core :refer :all])) (def test-address diff --git a/src/koans/15_refs.clj b/src/koans/16_refs.clj similarity index 98% rename from src/koans/15_refs.clj rename to src/koans/16_refs.clj index ea96e50..3395f29 100644 --- a/src/koans/15_refs.clj +++ b/src/koans/16_refs.clj @@ -1,4 +1,4 @@ -(ns koans.15-refs +(ns koans.16-refs (:require [koan-engine.core :refer :all])) (def the-world (ref "hello")) diff --git a/src/koans/16_atoms.clj b/src/koans/17_atoms.clj similarity index 97% rename from src/koans/16_atoms.clj rename to src/koans/17_atoms.clj index cc782d7..17d92dd 100644 --- a/src/koans/16_atoms.clj +++ b/src/koans/17_atoms.clj @@ -1,4 +1,4 @@ -(ns koans.16-atoms +(ns koans.17-atoms (:require [koan-engine.core :refer :all])) (def atomic-clock (atom 0)) diff --git a/src/koans/17_macros.clj b/src/koans/18_macros.clj similarity index 98% rename from src/koans/17_macros.clj rename to src/koans/18_macros.clj index d1dfcca..931dc75 100644 --- a/src/koans/17_macros.clj +++ b/src/koans/18_macros.clj @@ -1,4 +1,4 @@ -(ns koans.17-macros +(ns koans.18-macros (:require [koan-engine.core :refer :all])) (defmacro hello [x] diff --git a/src/koans/18_datatypes.clj b/src/koans/19_datatypes.clj similarity index 98% rename from src/koans/18_datatypes.clj rename to src/koans/19_datatypes.clj index 0bad914..d6eb31f 100644 --- a/src/koans/18_datatypes.clj +++ b/src/koans/19_datatypes.clj @@ -1,4 +1,4 @@ -(ns koans.18-datatypes +(ns koans.19-datatypes (:require [koan-engine.core :refer :all])) (defrecord Nobel [prize]) diff --git a/src/koans/19_java_interop.clj b/src/koans/20_java_interop.clj similarity index 96% rename from src/koans/19_java_interop.clj rename to src/koans/20_java_interop.clj index 4ebd9d5..8a7a6e2 100644 --- a/src/koans/19_java_interop.clj +++ b/src/koans/20_java_interop.clj @@ -1,4 +1,4 @@ -(ns koans.19-java-interop +(ns koans.20-java-interop (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/20_partition.clj b/src/koans/21_partition.clj similarity index 97% rename from src/koans/20_partition.clj rename to src/koans/21_partition.clj index 75dfc35..1a65620 100644 --- a/src/koans/20_partition.clj +++ b/src/koans/21_partition.clj @@ -1,4 +1,4 @@ -(ns koans.20-partition +(ns koans.21-partition (:require [koan-engine.core :refer :all])) (meditations diff --git a/src/koans/21_group_by.clj b/src/koans/22_group_by.clj similarity index 98% rename from src/koans/21_group_by.clj rename to src/koans/22_group_by.clj index c2d5377..01de423 100644 --- a/src/koans/21_group_by.clj +++ b/src/koans/22_group_by.clj @@ -1,4 +1,4 @@ -(ns koans.21-group-by +(ns koans.22-group-by (:require [koan-engine.core :refer :all])) (defn get-odds-and-evens [coll] diff --git a/src/koans/22_meta.clj b/src/koans/23_meta.clj similarity index 98% rename from src/koans/22_meta.clj rename to src/koans/23_meta.clj index 7d69081..45fec03 100644 --- a/src/koans/22_meta.clj +++ b/src/koans/23_meta.clj @@ -1,4 +1,4 @@ -(ns koans.22-meta +(ns koans.23-meta (:require [koan-engine.core :refer :all])) (def giants