From bd5f7eadd7968eb60dcf3630bcaac5a68a7c766e Mon Sep 17 00:00:00 2001 From: Manas Karekar Date: Sun, 3 Mar 2013 16:33:39 -0500 Subject: [PATCH 1/4] Exercise 9 - runtime polymorphism --- src/koans/09_runtime_polymorphism.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/koans/09_runtime_polymorphism.clj b/src/koans/09_runtime_polymorphism.clj index a8171ee..37816e7 100644 --- a/src/koans/09_runtime_polymorphism.clj +++ b/src/koans/09_runtime_polymorphism.clj @@ -7,19 +7,19 @@ "!"))) (defmulti diet (fn [x] (:eater x))) -(defmethod diet :herbivore [a] __) -(defmethod diet :carnivore [a] __) -(defmethod diet :default [a] __) +(defmethod diet :herbivore [a] (str (:name a) " eats veggies.")) +(defmethod diet :carnivore [a] (str (a :name) " eats animals.")) +(defmethod diet :default [a] (str "I don't know what " (:name a) " eats.")) (meditations "Some functions can be used in different ways - with no arguments" - (= __ (hello)) + (= "Hello World!" (hello)) "With one argument" - (= __ (hello "world")) + (= "Hello, you silly world." (hello "world")) "Or with many arguments" - (= __ + (= "Hello to this group: Peter, Paul, Mary!" (hello "Peter" "Paul" "Mary")) "Multimethods allow more complex dispatching" From 2e1d4feb3c587176f3c4392f00d069564f10c105 Mon Sep 17 00:00:00 2001 From: Manas Karekar Date: Sun, 3 Mar 2013 16:35:48 -0500 Subject: [PATCH 2/4] Updated readme --- README.md | 153 +----------------------------------------------------- 1 file changed, 1 insertion(+), 152 deletions(-) diff --git a/README.md b/README.md index f3cd403..991bedd 100644 --- a/README.md +++ b/README.md @@ -1,152 +1 @@ -# 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! - - -### 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/downloads). -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. - -The only things you'll need to run the Clojure Koans are: - -- JRE 1.5 or higher -- [clojure-1.5.0.jar](http://repo1.maven.org/maven2/org/clojure/clojure/1.5.0/clojure-1.5.0.zip) - -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). - -### Installing dependencies - -Dependencies are installed automatically with lein 2, but if you are still -using lein 1 run - -`lein deps` - -which will download all dependencies you need to run the Clojure koans. - - -### Running the Koans - -If you're running from the zipfile or using lein 1, 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 - -`lein koan 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). - -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 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): -any of them will work in these cases. - -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. - -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! - - -### 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 - -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: - -```clojure -(find-doc "vec") -(find-doc #"vec$") -(doc vec) -``` - -And if those still don't make sense: - -```clojure -(doc doc) -(doc find-doc) -``` - -will show you what those commands mean. - -You can exit the REPL with `CTRL-d` on any OS. - - -### Contributing - -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. - -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 -`resources/koans.clj`, and we'll get them in there! - -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. - - -### Contributors - -https://github.com/functional-koans/clojure-koans/contributors - - -### 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 -koans extremely simple and fun to use, and to 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 -[Ruby Koans](http://rubykoans.com) by [EdgeCase](http://github.com/edgecase). - - -### 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 -the terms of this license. +Simple solutions to the excellent clojure-koans. Putting them here for a simple reference during brain farts. From 2e0b4e4760c99894a39d7b4ef161bc1dd577e4e7 Mon Sep 17 00:00:00 2001 From: Manas Karekar Date: Sun, 3 Mar 2013 16:36:43 -0500 Subject: [PATCH 3/4] Exercise 9 - runtime polymorphism --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 991bedd..dfedf83 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -Simple solutions to the excellent clojure-koans. Putting them here for a simple reference during brain farts. +Simple solutions to the excellent clojure-koans. Putting them here as a quick reference during brain farts. From ca11a8c684cd278a155439a44f5db9a27e4d4471 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Sun, 3 Mar 2013 17:21:35 -0600 Subject: [PATCH 4/4] Bump koan-engine for bugfix Thanks to Manas Karekar for reporting. --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index f924a9b..769f6ce 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ -(defproject clojure-koans "0.4.8" +(defproject clojure-koans "0.4.9" :description "The Clojure koans." :dependencies [[org.clojure/clojure "1.5.0"] - [koan-engine "0.1.3"]] + [koan-engine "0.2.0"]] :dev-dependencies [[lein-koan "0.1.2"]] :profiles {:dev {:dependencies [[lein-koan "0.1.2"]]}} :plugins [[lein-koan "0.1.2"]]