2010-10-29 15:41:20 +00:00
|
|
|
# Clojure Koans
|
|
|
|
|
|
|
|
The Clojure Koans are a fun and easy way to get started with Clojure - no
|
|
|
|
experience assumed or required. Just follow the instructions below to start
|
|
|
|
making tests pass!
|
2010-01-15 01:13:17 +00:00
|
|
|
|
2010-05-27 18:22:26 +00:00
|
|
|
|
2010-01-15 01:13:17 +00:00
|
|
|
### Getting Started
|
|
|
|
|
2011-02-11 03:17:30 +00:00
|
|
|
The easiest and fastest way to get the koans up and running is to [download the
|
|
|
|
latest zip file from Github](https://github.com/functional-koans/clojure-koans/downloads).
|
2011-02-11 03:11:18 +00:00
|
|
|
This way, you'll have all the dependencies you need, including Clojure itself
|
|
|
|
and JLine, and you can skip the rest of this section (skip to "Running the
|
|
|
|
Koans").
|
|
|
|
|
|
|
|
If you're starting from a cloned or forked repo, that's cool too. This way
|
|
|
|
you'll be able to track your progress in Git, and see how your answers compare
|
2013-03-01 19:07:13 +00:00
|
|
|
to others, by checking out the project's Network tab. You might want to create
|
|
|
|
your own branch - that way if you pull back the latest koans from master, it'll
|
|
|
|
be a bit easier to manage the inevitable conflicts if we make changes to
|
|
|
|
exercises you've already completed.
|
2011-02-11 03:11:18 +00:00
|
|
|
|
|
|
|
The only things you'll need to run the Clojure Koans are:
|
2010-05-27 01:16:28 +00:00
|
|
|
|
|
|
|
- JRE 1.5 or higher
|
2013-05-03 21:54:36 +00:00
|
|
|
- [clojure-1.5.1.jar](http://repo1.maven.org/maven2/org/clojure/clojure/1.5.1/clojure-1.5.1.zip)
|
2010-05-27 18:22:26 +00:00
|
|
|
|
2013-03-01 19:07:13 +00:00
|
|
|
You can use [Leiningen](http://github.com/technomancy/leiningen) to
|
|
|
|
automatically install the Clojure jar in the right place. Leiningen will also
|
|
|
|
get you a couple more jarfiles, including JLine, which allows you some of the
|
|
|
|
functionality of readline (command-line history, for example).
|
2010-05-27 01:16:28 +00:00
|
|
|
|
2013-03-01 19:07:13 +00:00
|
|
|
### Installing dependencies
|
|
|
|
|
|
|
|
Dependencies are installed automatically with lein 2, but if you are still
|
|
|
|
using lein 1 run
|
2010-01-15 01:13:17 +00:00
|
|
|
|
|
|
|
`lein deps`
|
|
|
|
|
2010-11-01 18:13:48 +00:00
|
|
|
which will download all dependencies you need to run the Clojure koans.
|
2010-01-15 01:13:17 +00:00
|
|
|
|
2010-05-27 18:22:26 +00:00
|
|
|
|
2011-02-11 03:11:18 +00:00
|
|
|
### Running the Koans
|
2010-01-15 01:13:17 +00:00
|
|
|
|
2012-10-23 14:30:40 +00:00
|
|
|
If you're running from the zipfile or using lein 1, simply run
|
2010-01-15 01:13:17 +00:00
|
|
|
|
2010-11-02 01:09:15 +00:00
|
|
|
`script/run` on Mac/\*nix
|
2010-05-27 01:16:28 +00:00
|
|
|
|
2010-11-02 01:09:15 +00:00
|
|
|
`script\run` on Windows
|
2010-10-29 15:07:11 +00:00
|
|
|
|
2012-10-23 14:30:40 +00:00
|
|
|
If you're running from a checkout using lein 2, run the koans via
|
|
|
|
|
|
|
|
`lein koan run`
|
|
|
|
|
2011-06-16 23:01:43 +00:00
|
|
|
It's an auto-runner, so as you save your files with the correct answers, it will
|
2012-12-31 05:53:57 +00:00
|
|
|
advance you to the next koan or file (conveniently, all files are prefixed with
|
|
|
|
the sequence that you should follow).
|
2011-06-16 23:01:43 +00:00
|
|
|
|
2010-11-01 18:13:48 +00:00
|
|
|
You'll see something like this:
|
|
|
|
|
2013-02-26 02:47:02 +00:00
|
|
|
Now meditate on /home/colin/Projects/clojure-koans/src/koans/01_equalities.clj:3
|
2011-06-16 23:01:43 +00:00
|
|
|
---------------------
|
|
|
|
Assertion failed!
|
2010-11-01 18:13:48 +00:00
|
|
|
We shall contemplate truth by testing reality, via equality.
|
2011-06-16 23:01:43 +00:00
|
|
|
(= __ true)
|
2010-11-01 18:13:48 +00:00
|
|
|
|
2013-02-26 02:47:02 +00:00
|
|
|
The output is telling you that you have a failing test in the file named
|
|
|
|
`01_equalities.clj`, on line 3. So you just need to open that file up and make
|
|
|
|
it pass! You'll always be filling in the blanks to make tests pass.
|
|
|
|
Sometimes there could be several correct answers (or even an infinite number):
|
2013-05-03 21:54:36 +00:00
|
|
|
any of them will work in these cases. Some tests will pass even if you replace
|
|
|
|
the blanks with whitespace (or nothing) instead of the expected answer. Make sure
|
2013-03-04 04:06:39 +00:00
|
|
|
you give one correct expression to replace each blank.
|
2010-11-01 18:13:48 +00:00
|
|
|
|
|
|
|
The koans differ from normal TDD in that the tests are already written for you,
|
|
|
|
so you'll have to pay close attention to the failure messages, because up until
|
|
|
|
the very end, making a test pass just means that the next failure message comes
|
|
|
|
up.
|
|
|
|
|
2011-06-16 23:01:43 +00:00
|
|
|
While it might be easy (especially at first) to just fill in the blanks making
|
|
|
|
things pass, you should work thoughtfully, making sure you understand why the
|
|
|
|
answer is what it is. Enjoy your path to Clojure enlightenment!
|
2010-10-29 15:41:20 +00:00
|
|
|
|
2010-10-29 15:43:32 +00:00
|
|
|
|
2010-11-02 01:12:00 +00:00
|
|
|
### Trying more things out
|
|
|
|
|
|
|
|
There's a REPL (Read-Evaluate-Print Loop) included in the Clojure Koans. Just
|
|
|
|
run:
|
|
|
|
|
|
|
|
`script/repl` on Mac/\*nix
|
|
|
|
|
|
|
|
`script\repl` on Windows
|
|
|
|
|
2012-10-23 14:30:40 +00:00
|
|
|
If you're on lein 2, `lein repl` is what you want instead.
|
|
|
|
|
2010-11-02 01:12:00 +00:00
|
|
|
Here are some interesting commands you might try, once you're in a running REPL:
|
|
|
|
|
2011-09-24 17:45:43 +00:00
|
|
|
```clojure
|
|
|
|
(find-doc "vec")
|
|
|
|
(find-doc #"vec$")
|
|
|
|
(doc vec)
|
|
|
|
```
|
2010-11-02 01:12:00 +00:00
|
|
|
|
|
|
|
And if those still don't make sense:
|
|
|
|
|
2011-09-24 17:45:43 +00:00
|
|
|
```clojure
|
|
|
|
(doc doc)
|
|
|
|
(doc find-doc)
|
|
|
|
```
|
2010-11-02 01:12:00 +00:00
|
|
|
|
|
|
|
will show you what those commands mean.
|
|
|
|
|
|
|
|
You can exit the REPL with `CTRL-d` on any OS.
|
|
|
|
|
|
|
|
|
2010-10-29 15:43:32 +00:00
|
|
|
### Contributing
|
|
|
|
|
2012-10-23 14:30:40 +00:00
|
|
|
Patches are encouraged! Make sure the answer sheet still passes
|
|
|
|
(`script/test`, or `script\test` on Windows, or `lein koan test` on lein2), and
|
|
|
|
send a pull request.
|
2010-10-29 15:43:32 +00:00
|
|
|
|
2011-02-14 02:06:05 +00:00
|
|
|
The file ideaboard.txt has lots of good ideas for new koans to start, or things
|
|
|
|
to add to existing koans. So write some fun exercises, add your answers to
|
2011-11-29 19:50:45 +00:00
|
|
|
`resources/koans.clj`, and we'll get them in there!
|
2011-02-14 02:06:05 +00:00
|
|
|
|
|
|
|
Feel free to contact me (Colin Jones / trptcolin) on Github or elsewhere if you
|
|
|
|
have any questions or want more direction before you start pitching in.
|
2010-10-29 15:43:32 +00:00
|
|
|
|
|
|
|
|
2012-04-25 19:27:49 +00:00
|
|
|
### Contributors
|
|
|
|
|
|
|
|
https://github.com/functional-koans/clojure-koans/contributors
|
2011-02-08 13:23:08 +00:00
|
|
|
|
2010-10-29 15:41:20 +00:00
|
|
|
|
|
|
|
### Credits
|
|
|
|
|
|
|
|
These exercises were started by [Aaron Bedra](http://github.com/abedra) of
|
|
|
|
[Relevance, Inc.](http://github.com/relevance) in early 2010, as a learning
|
|
|
|
tool for newcomers to functional programming. Aaron's macro-fu makes these
|
2010-11-02 01:24:43 +00:00
|
|
|
koans extremely simple and fun to use, and to improve upon, and without
|
|
|
|
Relevance's initiative, this project would not exist.
|
2010-10-29 15:41:20 +00:00
|
|
|
|
|
|
|
Using the [koans](http://en.wikipedia.org/wiki/koan) metaphor as a tool for
|
|
|
|
learning a programming language started with the
|
|
|
|
[Ruby Koans](http://rubykoans.com) by [EdgeCase](http://github.com/edgecase).
|
|
|
|
|
2010-11-01 18:27:48 +00:00
|
|
|
|
|
|
|
### License
|
|
|
|
|
|
|
|
The use and distribution terms for this software are covered by the
|
|
|
|
Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
|
|
which can be found in the file epl-v10.html at the root of this distribution.
|
|
|
|
By using this software in any fashion, you are agreeing to be bound by
|
2012-04-25 19:27:49 +00:00
|
|
|
the terms of this license.
|