- Notifications
You must be signed in to change notification settings - Fork2.1k
A set of exercises for learning Clojure
functional-koans/clojure-koans
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The Clojure Koans are a fun way to get started with Clojure - no experienceassumed or required. Follow the instructions below to start making tests pass!
I recommend starting from a cloned or forked repo. This way you'll be able totrack your progress in Git. You might want to create your own branch - that wayif you pull back the latest koans from master, it'll be a bit easier to managethe inevitable conflicts if we make changes to exercises you've alreadycompleted.
You have a few options for installation:
- Install the dependencies for the koans (such as Clojure) on your machine
- Use Vagrant and the configuration in this repository
- Use Docker
Instructions for each option are below!
The only things you'll need to run the Clojure Koans are:
- JDK (I suggest version 8, but anything 6 or above should work fine)
- Leiningen, a build tool for Clojure
Once you've cloned this repo and installed the dependencies, you can run:
lein replto make sure all the dependencies get downloaded properly (and then(exit)when you want to quit). See below for details on the REPL.
Make sure you haveVagrant andVirtualBox installed.In the root directory of the project, execute:
vagrant upvagrant sshcd /vagrantlein koan runOnce you've gotDocker installed, you're basicallyall set. You can run these commands to get started:
To run koans:
docker run --rm -it -v $(pwd):/app -w /app clojure lein koan runTo start up a REPL:
docker run --rm -it -v $(pwd):/app -w /app clojure lein replRun the koans via:
lein koan run
If want to run directly from a REPL, once you are inside thelein repl prompt you can run the koans with
(exec "run")
Either way, it's an auto-runner, so as you save your files with the correctanswers, it will advance you to the next koan or file (conveniently, all filesare prefixed with the sequence that you should follow).
You'll see something like this:
Now meditate on /home/colin/Projects/clojure-koans/src/koans/01_equalities.clj:3---------------------Assertion failed!We shall contemplate truth by testing reality, via equality.(= __ true)The output is telling you that you have a failing test in the file named01_equalities.clj, on line 3. So you need to open that file up and makeit 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):any of them will work in these cases. Some tests will pass even if you replacethe blanks with whitespace (or nothing) instead of the expected answer. Make sureyou give one correct expression to replace each blank.
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 untilthe very end, making a test pass means that the next failure message comesup.
While it might be easy (especially at first) to fill in the blanks makingthings pass, you should work thoughtfully, making sure you understand why theanswer is what it is. Enjoy your path to Clojure enlightenment!
It's very useful to try things out in a REPL (Read-Evaluate-Print Loop)whenever you get stuck or curious. Run:
lein repland you'll be able to type expressions in, and see what output they produce.
Here are some interesting commands you might try, once you're in a running REPL:
(find-doc"vec")(find-doc#"vec$")(doc vec)
And if those still don't make sense:
(doc doc)(doc find-doc)
will show you what those commands mean.
You can exit the REPL withCTRL-d,(exit), or(quit).
Patches are encouraged! Make sure the answer sheet still passes(lein koan test), and send a pull request.
The file ideaboard.txt has lots of good ideas for new koans to start, or thingsto add to existing koans. So write some fun exercises, add your answers toresources/koans.clj, and we'll get them in there!
Please follow the guidelines inhttp://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html forcommit messages, and put your code in a feature branch (not master) beforemaking the pull request. This makes patches easier to review.
Feel free to contact me (Colin Jones / trptcolin) on Github or elsewhere if youhave any questions or want more direction before you start pitching in.
https://github.com/functional-koans/clojure-koans/contributors
These exercises were started byAaron Bedra ofRelevance, Inc. in early 2010, as a learningtool for newcomers to functional programming. Aaron's macro-fu makes thesekoans clear and fun to use and improve upon, and without Relevance'sinitiative, this project would not exist.
Using thekoans metaphor as a tool forlearning a programming language started with theRuby Koans byEdgeCase.
The use and distribution terms for this software are covered by theEclipse 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 bythe terms of this license.
About
A set of exercises for learning Clojure
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.