

Clojure Distilled - nickmain
http://yogthos.github.io/ClojureDistilled.html

======
dschiptsov
I am really suggesting to try some classic Scheme course first, like my
favorite CS61A by Brian Harvey, or that wonderful Racket-based course (what's
the difference?) on Coursera by Gregor Kiczales (which is worth watching even
if you are mere a brainwashed Java dev).

Another way is through pg's books, especially, of course, "On Lisp" and Arc
tutorial and then arc.arc (original version from the 2009 arc3.tar which isn't
cluttered with silly docstrings and other nonsense).

There is also the way of CL. For that there is pg's ANSI CL, but before that a
much better "CL Language Concepts" from Symbolics (pdfs are available from
bitsavers).

Then, perhaps, one will have slightly different view of what Clojure is
really. Yes, it is a real marvel of software craftsmanship, especially that it
was originally a solo effort, but no, there is no miracles in it.)

~~~
AlexeyBrin

        which is worth watching even if you are mere a brainwashed Java dev
    

and this is why so many people are repelled by the Lisp (or Scheme)
evangelism. I don't particularly like Java, but I use it for Android
development. Calling people _brainwashed_ because they are using Java is
simply rude.

~~~
dschiptsov
In my opinion Java is the biggest fraud and waste in the history of IT (next
comes SAP) - nothing but hype, ignorant parroting of silly memes by "managers"
(so-called bandwagon and peer effects) lies, and taking advantage of ignorant.

People who "know no better" (cannot even visit the rosettacode.org, dismissed
plain old C - these evil pointers!, Erlang - functional programming is for
academy, or CL - not an enterprise level, etc, etc) are, well, brainwashed.

I am not blaming the people, I am just describing reality as I see it, and my
view is by no means new or even "original".

Java was just a way to make money (in 2000s) like "derivatives traders" in the
last 10 years. Same manipulations, same techniques.

For example, almost all of the very few popular apps I have installed on my
Nexus4 are _NDK_ apps - FB, Viber, Skype - you name it.

~~~
AlexeyBrin
Java is just a programming tool and, while I would have preferred to use C++14
for all my Android projects, it is what it is ( _NDK_ make sense only for
heavy duty applications).

Now, imagine for a second that you are a junior programmer, that only knows
Java. You've heard of this thing called Clojure and you want to read and learn
more about it. What would you think if someone called you _brainwashed_ just
because you only know Java ? For most people this means EOD (end of
discussion). Calling someone _brainwashed_ just because he doesn't have your
level of expertise with other languages will just make it ignore the good
parts of your comment.

In the end it is about what is more important to you: vent some steam about
how much you hate Java or guide someone to learn more about a Lisp language.

~~~
dschiptsov
Not so long ago a student of a good school in US would know Scheme and C, not
Java or Python, and the move to Java as the language for teaching CS is, in my
opinion, the result of the same regrettable process of brainwashing.

btw, I never talk Java issues in a context of a personally, only in a broader
sense of a "social phenomena" partly explained by well studied "effects" in
social psychology.

Unfortunately, Clojure will not be suitable for Android development in
observable future exactly because "Java" cannot fulfill its promises -
Clojure's runtime is "too heavy and too slow" (too wasteful) to run even on a
newest smartphone hardware, and in this, again, so-called reality re-asserted
itself.

------
d_t_w
I've been working with Clojure for 18 months now, after a bit more than 10
years of Java. I'm having so much fun I don't think I could ever go back.

Also, this is an excellent summary / introduction to key clojure concepts,
well done to the author.

~~~
kjjw
Seconded. I was working with a mix of Java and Ruby for roughly a decade. I've
been working full time with Clojure for about two years now, and on and off
for a couple of years before that.

Fantastic introductory guide. Clojure really needs something like this. There
are some good books on Clojure but I find they are aimed at either the
determined beginner or the experienced (or both.) This though I feel I could
pass around to anyone that wants to get an idea of what Clojure is about.

------
killercup
I'm not done reading but it seems like a very nice introduction to people not
familiar with the function style of programming.

This is also one of the few document that can be converted from html to epub
without much pain. It looks quite good with

    
    
        pandoc ClojureDistilled.html -o ClojureDistilled.epub --indented-code-classes=clojure

------
fdsary
I love clojure, and dream of the day I can work with it.

But do you know why more people get into ruby or js? It's community is
beginner friendly. Most texts on the subject of lisps feel like wannabe
dissertations, preferably with the Computer Modern font and 5 pages long.

~~~
oinksoft
I would never suggest a programmer learn Clojure as their first language,
because of the enormous Java stacktraces. Then there's the setup involved
(Java, usually Leiningen) to get to "Hello, World" compared to Python or Ruby.
Just too many places where the student can get seriously stuck. Clojure's
strengths (immutable structures, expression freedom, macros, Java interop,
JVM) are not relevant to the new programmer.

~~~
raspasov
Yes, the Java stack traces are probably the worst "ugly" thing in Clojure but
from my experience the simplicity of syntax (not to be confused with
familiarity, familiar != simple) makes it much easier for someone who's never
programmed before to start writing Clojure code vs many other languages where
there's a lot of syntax to that you simply need to "know" to get going.

Also, on a more advanced note, I've used
[https://github.com/ptaoussanis/timbre](https://github.com/ptaoussanis/timbre)
with great success to get nicely formatted and colored Clojure errors and
stack traces.

------
zeroyzeroa
Extracting keys from maps into a definition, with common-lisp (using my macro
defk)

(defk login (user pass) (and (string= user "Bob") (string= pass "secret")))

(login (list-to-hash '(user "Bob" pass "secret")) (list-to-hash '(user "Bob"
pass "secret"))

Given the following definitions:

(defmacro defk(name h-list &rest body) `(defun ,name (h) (let ,h-list ,@(loop
for k in h-list collect `(setq ,k (gethash (quote ,k) h))) ,@body)))

(defun list-to-hash(list) (let ((h (make-hash-table))) (loop for (k v) on list
by #'cddr do (setf (gethash k h) v)) h))

~~~
malisper
It's probably more idiomatic to implement something similar to the with-slots
macro by using symbol-macrolet:

    
    
      (defmacro with-keys (keys table &body body)
        (let ((gtable (gensym)))
          `(let ((,gtable ,table))
             (symbol-macrolet ,(loop for k in keys
                                     collect `(,k (gethash ',k ,gtable)))
               ,@body))))
    

This way you can both access and set the keys:

    
    
      CL-USER> (defparameter *table* (make-hash-table))
      *TABLE*
      CL-USER> (setf (gethash 'a *table*) 10
                     (gethash 'b *table*) 20)
      20
      CL-USER> (with-keys (a b) *table*
                 (list a b))
      (10 20)
      CL-USER> (with-keys (a b) *table*
                 (setf a 100
                       b 200))
      200
      CL-USER> (list (gethash 'a *table*)
                     (gethash 'b *table*))
      (100 200)
    

If you really want to destructure a hash-table when its an argument, it is not
much harder to write a new version of defun on top of with-keys or
zeroyzeroa's solution (his/hers only takes a single argument).

------
arms
I'm currently learning Clojure. For all the "aha!" moments, there are plenty
of "WTFs?", too. Not that it's a fault of the language, it's just that it
requires a different way of looking at things. I've only skimmed this article,
but look forward to reading it in depth later. Thanks!

I'd be interested if anyone has some similar pieces to share.

~~~
verisimilidude
Most of my Clojure WTFs were not related to the language itself, but rather
the tooling. This was years ago, but everyone used to say, "Before diving into
Clojure, you should really learn _emacs_ and all these other things first."
I'm glad I ignored them and sputtered along in a text editor while learning
the basics of the language, because I would've otherwise burnt out.

With apps like Light Table now available, maybe beginners have an easier ramp
these days.

~~~
arms
Good to know! I started with emacs, but decided to use Light Table for now.
Nothing against emacs, but I don't want to make things harder by learning a
new language _and_ a new editor at the same time. Aside from Light Table (and
presumably Leiningen) do you have any other tooling recommendations?

~~~
craigching
I will say that cider has done a very nice job of getting interactive
development using Emacs to work well. I am a 20+ year Emacs user and _love_
working with Clojure via cider. I will say that I think getting started with
Light Table is a great way to start, but don't leave Emacs too far behind!

Good luck go you!

~~~
mendort
I also am a long time emacs user, but whenever a plugin freezes emacs I
immediately stop using it. Is is cider now stable? I know nrepl.el would crash
emacs frequently if you asked it to evaluate the wrong thing.

~~~
willismichael
I'm not sure how long this feature has been around, but C-c C-b will abort any
running evaluation(s)... I've used it more than once to save a non-responsive
cider repl session.

~~~
kjjw
Well I've been using cider / nrepl.el for a long time and never knew this.
Don't know how I missed it.

Thank you.

------
fnordsensei

      Higher order functions can be easily chained 
      together to create complex transformations:
    
      (filter even?
        (map #(* 3 %) [1 2 3 4 5])) 
      =>(6 12)
    

This will need to be updated to make use of transducers, I guess.

~~~
rbanffy
Only if it enhances the poetic value.

------
jdeisenberg
It's a very good summary.

------
profil
When using rawgit, please follow the owners request about using cdn.rawgit.com
for anything that might result in heavy traffic. I guess links submitted to HN
often results in heavy traffic.

[https://rawgit.com/faq#diff-between-rawgit-and-
cdn](https://rawgit.com/faq#diff-between-rawgit-and-cdn)

~~~
infogulch
So the url should be changed to this (which loads for me):

[https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...](https://cdn.rawgit.com/yogthos/yogthos.github.com/master/ClojureDistilled.html)

------
daveloyall
That link is down for me, but I think this is the same content?

[http://yogthos.github.io/ClojureDistilled.html](http://yogthos.github.io/ClojureDistilled.html)

~~~
sternenseemann
also this works via rawgit:
[https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...](https://cdn.rawgit.com/yogthos/yogthos.github.com/master/ClojureDistilled.html)

~~~
jkrems
But the "real" URL also would have proper CSS etc. and looks slightly less
broken.

------
tim333
The main link's stopped working with a message to use the cdn version instead:

[https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...](https://cdn.rawgit.com/yogthos/yogthos.github.com/master/ClojureDistilled.html)

------
nelsonenzo
correct link here
[https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...](https://cdn.rawgit.com/yogthos/yogthos.github.com/master/ClojureDistilled.html)

------
sailfast
I'm really enjoying reading this - thanks!

For those that don't want to tax the owner of rawgit - try github pages - it's
just HTML, right?
[http://yogthos.github.io/ClojureDistilled.html](http://yogthos.github.io/ClojureDistilled.html)

