Learn Clojure with Clojure Koans
clojurekoans.com
clojurekoans.com
As an example:
"But watch out if you try to pop nothing"
(= __ (try
(pop '())
(catch IllegalStateException e "No dice!")))
That code causes an error that looks like this: Problem in /home/clueless/clojure-koans/src/koans/02_lists.clj
---------------------
Assertion failed!
But watch out if you try to pop nothing
(= __ (try (pop (quote ())) (catch IllegalStateException e "No dice!")))
That's just a transliteration of the Clojure expression from my source code. It's not even as good as a line number, because it's not greppable. If I were actually to encounter this in a failing test, you had better believe I would want to know what the right-hand-side actually evaluated to in context, not just what the compiled expression looks like.This is basically the worst part of Clojure (and only on the JVM at that): catching a Java exception.
I know that's not your point but --and I'm a huge Clojure fan-- seeing a Java idiosynchrasy like that one makes me want to give up Clojure : (
"Conjoining an element to a list can be done in the reverse order"
(= __ (conj '(:a :b :c :d :e) 0))
Well OK, so is `conj` just `cons` with reversed argument order, or does it append to the other end of the list? My Lisp intuition tells me that the first is more likely, but the test failure doesn't show you anything, you have to use trial and error or fire up a REPL.e.g. (conj '(:a :b :c) :d :e :f) returns (:f :e :d :a :b :c)
I agree it does make it easier to solve when you can see what you're trying to evaluate to. It was actually a conscious decision to make that not be the case, because it seemed too easy to just fill in the blanks without thinking about what should go there.
I remember I did: the koans first, then tried several exercises on the 4clojure website, then learned about Leinengen and only then I moved into 'projects'.
Unless they expect the new user to spend significant time learning about that tool before moving on to their koans, I think it'd really be much better to have a short how-to for that.
Learn Leiningen- not only because it makes Clojure simple and pleasurable to use, but because it'd be a fantastic tool no matter what language it was part of.
Project skeletons (new new), command line scripting (via lein exec), deployment, the wonderful 'lein ring server', custom plugins... and for those who just want to get their feet wet, 'lein repl' brings the ocean to you.
Specifically:
git clone git@github.com:functional-koans/clojure-koans.git
cd clojure-koans
lein deps
lein koan runKudos to the authors, and you have a thumbs up from me.
- find a function / aspect of Clojure that calls my attention
- read the doc / try to understand the rationale
- give it a sample use case, try to connect it with previous lessons
- recur!
Now I'm into 4clojure to keep on practising the syntax and to get my mind to think _the functional way_
Any other resource to be suggested?
I need to revisit them, but the thornier (for me) problems kept distracting me from other work.