Merge branch 'master' into master

This commit is contained in:
frankiezdh 2017-11-23 14:15:20 +08:00 committed by GitHub
commit 3436b55776
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 63 deletions

View file

@ -1,28 +1,20 @@
# Clojure Koans # Clojure Koans
The Clojure Koans are a fun and easy way to get started with Clojure - no The Clojure Koans are a fun way to get started with Clojure - no experience
experience assumed or required. Just follow the instructions below to start assumed or required. Follow the instructions below to start making tests pass!
making tests pass!
## Getting Started ## Getting Started
The easiest and fastest way to get the koans up and running is to [download the I recommend starting from a cloned or forked repo. This way you'll be able to
latest zip file from Github](https://github.com/functional-koans/clojure-koans/releases). track your progress in Git. You might want to create your own branch - that way
This way, you'll have all the dependencies you need, including Clojure itself if you pull back the latest koans from master, it'll be a bit easier to manage
and JLine, and you can skip the rest of this section (skip to "Running the the inevitable conflicts if we make changes to exercises you've already
Koans"). completed.
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
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.
You have a few options for installation: You have a few options for installation:
- Install the dependencies for the koans (such as Clojure) on your machine, - Install the dependencies for the koans (such as Clojure) on your machine
- Use Vagrant and the configuration in this repository - Use Vagrant and the configuration in this repository
- Use Docker - Use Docker
@ -33,22 +25,17 @@ Instructions for each option are below!
The only things you'll need to run the Clojure Koans are: The only things you'll need to run the Clojure Koans are:
- JRE 1.6 or higher - JDK (I suggest version 8, but anything 6 or above should work fine)
- [clojure-1.8.0.jar](http://repo1.maven.org/maven2/org/clojure/clojure/1.8.0/clojure-1.8.0.zip) - [Leiningen](http://github.com/technomancy/leiningen), a build tool for Clojure
You can use [Leiningen](http://github.com/technomancy/leiningen) to Once you've cloned this repo and installed the dependencies, you can run:
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).
Dependencies are installed automatically with lein 2, but if for some reason ```
you're on lein 1 and can't upgrade, you'll need to run lein repl
```
`lein deps` to make sure all the dependencies get downloaded properly (and then `(exit)`
when you want to quit). See below for details on the REPL.
which will download all dependencies you need to run the Clojure koans.
I strongly recommend that you upgrade to lein 2 instead!
### Installation with Vagrant ### Installation with Vagrant
@ -76,7 +63,7 @@ To run koans:
docker run --rm -it -v $(pwd):/app -w /app clojure lein koan run docker run --rm -it -v $(pwd):/app -w /app clojure lein koan run
``` ```
To execute REPL: To start up a REPL:
``` ```
docker run --rm -it -v $(pwd):/app -w /app clojure lein repl docker run --rm -it -v $(pwd):/app -w /app clojure lein repl
@ -85,13 +72,7 @@ docker run --rm -it -v $(pwd):/app -w /app clojure lein repl
## Running the Koans ## Running the Koans
If you're running from the zipfile, simply run Run the koans via:
`script/run` on Mac/\*nix
`script\run` on Windows
If you're running from a checkout using lein 2, run the koans via
`lein koan run` `lein koan run`
@ -99,9 +80,9 @@ If want to run directly from a REPL, once you are inside the `lein repl` prompt
`(exec "run")` `(exec "run")`
It's an auto-runner, so as you save your files with the correct answers, it will Either way, it's an auto-runner, so as you save your files with the correct
advance you to the next koan or file (conveniently, all files are prefixed with answers, it will advance you to the next koan or file (conveniently, all files
the sequence that you should follow). are prefixed with the sequence that you should follow).
You'll see something like this: You'll see something like this:
@ -112,7 +93,7 @@ You'll see something like this:
(= __ true) (= __ true)
The output is telling you that you have a failing test in the file named 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 `01_equalities.clj`, on line 3. So you need to open that file up and make
it pass! You'll always be filling in the blanks to make tests pass. 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): 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 replace any of them will work in these cases. Some tests will pass even if you replace
@ -121,24 +102,24 @@ you give one correct expression to replace each blank.
The koans differ from normal TDD in that the tests are already written for you, 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 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 the very end, making a test pass means that the next failure message comes
up. up.
While it might be easy (especially at first) to just fill in the blanks making While it might be easy (especially at first) to fill in the blanks making
things pass, you should work thoughtfully, making sure you understand why the things pass, you should work thoughtfully, making sure you understand why the
answer is what it is. Enjoy your path to Clojure enlightenment! answer is what it is. Enjoy your path to Clojure enlightenment!
## Trying more things out ## Trying more things out
There's a REPL (Read-Evaluate-Print Loop) included in the Clojure Koans. Just It's very useful to try things out in a REPL (Read-Evaluate-Print Loop)
run: whenever you get stuck or curious. Run:
`script/repl` on Mac/\*nix ```
lein repl
```
`script\repl` on Windows and you'll be able to type expressions in, and see what output they produce.
If you're on lein 2, `lein repl` is what you want instead.
Here are some interesting commands you might try, once you're in a running REPL: Here are some interesting commands you might try, once you're in a running REPL:
@ -157,7 +138,8 @@ And if those still don't make sense:
will show you what those commands mean. will show you what those commands mean.
You can exit the REPL with `CTRL-d` on any OS. You can exit the REPL with `CTRL-d`, `(exit)`, or `(quit)`.
## Contributing ## Contributing
@ -187,8 +169,8 @@ https://github.com/functional-koans/clojure-koans/contributors
These exercises were started by [Aaron Bedra](http://github.com/abedra) of These exercises were started by [Aaron Bedra](http://github.com/abedra) of
[Relevance, Inc.](http://github.com/relevance) in early 2010, as a learning [Relevance, Inc.](http://github.com/relevance) in early 2010, as a learning
tool for newcomers to functional programming. Aaron's macro-fu makes these tool for newcomers to functional programming. Aaron's macro-fu makes these
koans extremely simple and fun to use, and to improve upon, and without koans clear and fun to use and improve upon, and without Relevance's
Relevance's initiative, this project would not exist. initiative, this project would not exist.
Using the [koans](http://en.wikipedia.org/wiki/koan) metaphor as a tool for Using the [koans](http://en.wikipedia.org/wiki/koan) metaphor as a tool for
learning a programming language started with the learning a programming language started with the

View file

@ -1,10 +1,10 @@
(defproject clojure-koans "0.5.1-SNAPSHOT" (defproject clojure-koans "0.5.1-SNAPSHOT"
:description "The Clojure koans." :description "The Clojure koans."
:dependencies [[org.clojure/clojure "1.8.0"] :dependencies [[org.clojure/clojure "1.8.0"]
[koan-engine "0.2.3"]] [koan-engine "0.2.4"]]
:dev-dependencies [[lein-koan "0.1.3"]] :dev-dependencies [[lein-koan "0.1.4"]]
:profiles {:dev {:dependencies [[lein-koan "0.1.3"]]}} :profiles {:dev {:dependencies [[lein-koan "0.1.4"]]}}
:repl-options {:init-ns koan-engine.runner :repl-options {:init-ns koan-engine.runner
:init ^:displace (do (use '[koan-engine.core]))} :init ^:displace (do (use '[koan-engine.core]))}
:plugins [[lein-koan "0.1.3"]] :plugins [[lein-koan "0.1.4"]]
:main koan-engine.runner/exec) :main koan-engine.runner/exec)

View file

@ -90,7 +90,7 @@
10 10
60 60
15 15
30] "AACC"]
"___" [+ "___" [+
* *
(fn [f] (f 5)) (fn [f] (f 5))
@ -127,7 +127,7 @@
[0 1 2 3 4] [0 1 2 3 4]
10 10
95 95
(range 20) [1 2 4 8 16 32 64 128]
:a] :a]
"___" [(fn [x] x)]}] "___" [(fn [x] x)]}]

View file

@ -23,7 +23,7 @@
(= 15 (#(+ %1 %2 %3) 4 5 6)) (= 15 (#(+ %1 %2 %3) 4 5 6))
"Arguments can also be skipped" "Arguments can also be skipped"
(= 30 (#(* 15 %2) 1 2)) (= __ (#(str "AA" %2) "bb" "CC"))
"One function can beget another" "One function can beget another"
(= 9 (#(+ %1 %2) 4 5)) (= 9 (#(+ %1 %2) 4 5))

View file

@ -17,12 +17,12 @@
(drop __ (range 100))) (drop __ (range 100)))
"Iteration provides an infinite lazy sequence" "Iteration provides an infinite lazy sequence"
(= __ (take 20 (iterate inc 0))) (= __ (take 8 (iterate (fn [x] (* x 2)) 1)))
"Repetition is key" "Repetition is key"
(= [:a :a :a :a :a :a :a :a :a :a] (= [:a :a :a :a :a :a :a :a :a :a]
(repeat 10 __)) (repeat 10 __))
"Iteration can be used for repetition" "Iteration can be used for repetition"
(= (repeat 100 :hello) (= (repeat 100 "hello")
(take 100 (iterate ___ :hello)))) (take 100 (iterate ___ "hello"))))