commit
b64b17fc51
202
.gitignore
vendored
202
.gitignore
vendored
@ -1,11 +1,203 @@
|
||||
*~
|
||||
bin
|
||||
classes
|
||||
lib
|
||||
releases
|
||||
target
|
||||
*.jar
|
||||
.DS_Store
|
||||
|
||||
# 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-plugins
|
||||
.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-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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"]]}}
|
||||
|
@ -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}
|
||||
|
70
src/koans/02_strings.clj
Normal file
70
src/koans/02_strings.clj
Normal file
@ -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?")))
|
@ -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!"))))
|
||||
|
@ -1,4 +1,4 @@
|
||||
(ns koans.03-vectors
|
||||
(ns koans.04-vectors
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -1,4 +1,4 @@
|
||||
(ns koans.04-sets
|
||||
(ns koans.05-sets
|
||||
(:require [koan-engine.core :refer :all]
|
||||
[clojure.set :as set]))
|
||||
|
@ -1,4 +1,4 @@
|
||||
(ns koans.05-maps
|
||||
(ns koans.06-maps
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -1,4 +1,4 @@
|
||||
(ns koans.06-functions
|
||||
(ns koans.07-functions
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defn multiply-by-ten [n]
|
@ -1,4 +1,4 @@
|
||||
(ns koans.07-conditionals
|
||||
(ns koans.08-conditionals
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defn explain-exercise-velocity [exercise-term]
|
@ -1,4 +1,4 @@
|
||||
(ns koans.08-higher-order-functions
|
||||
(ns koans.09-higher-order-functions
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -1,4 +1,4 @@
|
||||
(ns koans.09-runtime-polymorphism
|
||||
(ns koans.10-runtime-polymorphism
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defn hello
|
@ -1,4 +1,4 @@
|
||||
(ns koans.10-lazy-sequences
|
||||
(ns koans.11-lazy-sequences
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -1,4 +1,4 @@
|
||||
(ns koans.11-sequence-comprehensions
|
||||
(ns koans.12-sequence-comprehensions
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -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))
|
@ -1,4 +1,4 @@
|
||||
(ns koans.13-recursion
|
||||
(ns koans.14-recursion
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defn is-even? [n]
|
@ -1,4 +1,4 @@
|
||||
(ns koans.14-destructuring
|
||||
(ns koans.15-destructuring
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(def test-address
|
@ -1,4 +1,4 @@
|
||||
(ns koans.15-refs
|
||||
(ns koans.16-refs
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(def the-world (ref "hello"))
|
@ -1,4 +1,4 @@
|
||||
(ns koans.16-atoms
|
||||
(ns koans.17-atoms
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(def atomic-clock (atom 0))
|
@ -1,4 +1,4 @@
|
||||
(ns koans.17-macros
|
||||
(ns koans.18-macros
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defmacro hello [x]
|
@ -1,4 +1,4 @@
|
||||
(ns koans.18-datatypes
|
||||
(ns koans.19-datatypes
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defrecord Nobel [prize])
|
@ -1,4 +1,4 @@
|
||||
(ns koans.19-java-interop
|
||||
(ns koans.20-java-interop
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -1,4 +1,4 @@
|
||||
(ns koans.20-partition
|
||||
(ns koans.21-partition
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
@ -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]
|
@ -1,4 +1,4 @@
|
||||
(ns koans.22-meta
|
||||
(ns koans.23-meta
|
||||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(def giants
|
Loading…
Reference in New Issue
Block a user