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
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!
The Clojure Koans are a fun way to get started with Clojure - no experience
assumed or required. Follow the instructions below to start making tests pass!
## Getting Started
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/releases).
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
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.
I recommend starting from a cloned or forked repo. This way you'll be able to
track your progress in Git. 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:
- 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 Docker
@ -33,22 +25,17 @@ Instructions for each option are below!
The only things you'll need to run the Clojure Koans are:
- JRE 1.6 or higher
- [clojure-1.8.0.jar](http://repo1.maven.org/maven2/org/clojure/clojure/1.8.0/clojure-1.8.0.zip)
- JDK (I suggest version 8, but anything 6 or above should work fine)
- [Leiningen](http://github.com/technomancy/leiningen), a build tool for Clojure
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).
Once you've cloned this repo and installed the dependencies, you can run:
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`
which will download all dependencies you need to run the Clojure koans.
I strongly recommend that you upgrade to lein 2 instead!
to make sure all the dependencies get downloaded properly (and then `(exit)`
when you want to quit). See below for details on the REPL.
### Installation with Vagrant
@ -76,7 +63,7 @@ To run koans:
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
@ -85,13 +72,7 @@ docker run --rm -it -v $(pwd):/app -w /app clojure lein repl
## Running the Koans
If you're running from the zipfile, simply run
`script/run` on Mac/\*nix
`script\run` on Windows
If you're running from a checkout using lein 2, run the koans via
Run the koans via:
`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")`
It's an auto-runner, so as you save your files with the correct answers, it will
advance you to the next koan or file (conveniently, all files are prefixed with
the sequence that you should follow).
Either way, it's an auto-runner, so as you save your files with the correct
answers, it will advance you to the next koan or file (conveniently, all files
are prefixed with the sequence that you should follow).
You'll see something like this:
@ -112,7 +93,7 @@ You'll see something like this:
(= __ true)
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.
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
@ -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,
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.
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
answer is what it is. Enjoy your path to Clojure enlightenment!
## Trying more things out
There's a REPL (Read-Evaluate-Print Loop) included in the Clojure Koans. Just
run:
It's very useful to try things out in a REPL (Read-Evaluate-Print Loop)
whenever you get stuck or curious. Run:
`script/repl` on Mac/\*nix
```
lein repl
```
`script\repl` on Windows
If you're on lein 2, `lein repl` is what you want instead.
and 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:
@ -157,7 +138,8 @@ And if those still don't make sense:
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
@ -187,8 +169,8 @@ https://github.com/functional-koans/clojure-koans/contributors
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
koans extremely simple and fun to use, and to improve upon, and without
Relevance's initiative, this project would not exist.
koans clear and fun to use and improve upon, and without Relevance's
initiative, this project would not exist.
Using the [koans](http://en.wikipedia.org/wiki/koan) metaphor as a tool for
learning a programming language started with the

View file

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

View file

@ -79,7 +79,7 @@
false
"February"
1 "January"
:c 3
:c 3
2
2010 2014 2018
"PyeongChang" "Sochi" "Vancouver"
@ -90,7 +90,7 @@
10
60
15
30]
"AACC"]
"___" [+
*
(fn [f] (f 5))
@ -127,7 +127,7 @@
[0 1 2 3 4]
10
95
(range 20)
[1 2 4 8 16 32 64 128]
:a]
"___" [(fn [x] x)]}]

View file

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

View file

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