
Learn Clojure with Clojure Koans - oskarth
http://clojurekoans.com/
======
sirclueless
I don't know if this is just their test runner or whether it is a problem in
Clojure proper, but it's really frustrating to see "Assertion failed" with
zero description of the runtime error. I have to fire up a REPL and reverse
engineer the expected value, instead of just observing what the expression
evaluates to as in the ruby koans.

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.

~~~
martinced
This is some kind of a sad example you put here on HN...

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 : (

~~~
sirclueless
In this case it's a Java wart, yes, but the same thing happens with other
parts of the language. Another example:

    
    
        "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.

~~~
cicero
There's more to conj. It does a cons for lists, but works differently for
other types of collections. You might find it helpful to lookup things in
ClojureDocs. <http://clojuredocs.org/clojure_core/clojure.core/conj>

------
Sandman
Exercises on <http://www.4clojure.com> seem like a much easier way to get your
feet wet with Clojure. It's good when new users can try a language out right
in their browsers, without having to install any additional software.

~~~
cicero
I agree that 4clojure.com seems an easier way to get started. However, if
you're already setup with Clojure on your machine, using clojurekoans.com has
the advantage of allowing you to work in your editor of choice.

------
pivo
Since this is for new Clojure users I think the install instructions should
include how to install the koans with Leiningen. The instructions say to
install Leiningen but once you've got that working you won't know how to use
it to install the koans.

~~~
eccp
I don't agree, I'd advise not to try Leiningen until you're comfortable enough
with the parenthesis, the REPL and finish the koans themselves. This is
'getting your feet wet on Clojure', koans style. No need to introduce yet
another tool when you're not dealing with the issues which Leinengen solves:
managing library dependencies and configuration.

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'.

~~~
nelsonweiss
Politely, I'd advise the opposite.

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.

~~~
kinleyd
My initial reaction was to upvote @eccp, based on my experience with leiningen
the first time round. Long story short: went around in circles following
outdated (but seemingly comprehensive) guides that twisted my mind with
hopeless combinations of Ant, Maven, Leiningen, emacs, slime and swank, among
others. Basically gave up after a while, but was fortunate to get some
encouragement here on HN, and went back in with just leiningen and emacs. I
recall that was just the right mix, and as you say, lein repl pretty much
brought the ocean to me.

------
zephjc
You can also do them online at <http://www.4clojure.com/>

------
Posibyte
This is the first time I've seen something like this, but it's greatly
broadened my knowledge of Clojure over the past few hours. I've always had
trouble trying to find out where to begin. Lisps are foreign to me, and
functional programming was and is still a mostly foreign concept. However,
things like this that are so simple and understandable make such great
introductions.

Kudos to the authors, and you have a thumbs up from me.

------
vemv
As for koans + tdd as the means for learning a lang, ymmv. I for one prefer an
undisciplined, bootstrappy approach:

\- 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!

~~~
Cymen
As a somewhat recent practicer of tdd, I find that the koans + tdd approach is
more rounded: I'm forced to learn/use a function/aspect that I might have
glossed over. And occasionally a particularly nice usage of syntax jumps out
and gets adopted.

------
apinstein
Does anyone know how to run these in Light Table? I really love the idea of
that and was hoping to try it to learn Clojure, but I have absolutely no idea
how to run the koans from inside Light Table.

~~~
myko
I did 'lein koan run' in my terminal and opened the first file up in
LightTable, then made my first edit and hit save - the terminal updated
automatically as I saved my changes.

------
bernatfp
I've done them as an introduction to the Clojure language and it's been great.

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?

~~~
arkx
I've had fun solving the Rosalind collection of introductory bioinformatics
problems: <http://rosalind.info/problems/list-view/>

~~~
tom_b
I was playing with the Rosalind problems using clojure. It was great fun,
although I did evil things with the clojure combinatorics library and in one
memorable session, datomic datalog.

I need to revisit them, but the thornier (for me) problems kept distracting me
from other work.

------
sathish316
There is an online version of Clojure koans built using Noir available here:
<http://clojurekoans.herokuapp.com>

------
dschiptsov
Has nothing to do neither with oriental philosophy nor programming.)

~~~
willismichael
The most maddening part of your comment is the unbalanced paren at the end.

