Clojure Distilled
yogthos.github.io
yogthos.github.io
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.)
I see where you're coming from, SLW.
And people wonder why Lisp advocates have such a bad reputation.
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.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.
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.
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.
Also, this is an excellent summary / introduction to key clojure concepts, well done to the author.
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.
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=clojureBut 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.
http://tryclj.com/ http://www.braveclojure.com/ http://aphyr.com/posts/301-clojure-from-the-ground-up-welcom... http://clojurekoans.com/ http://www.4clojure.com/
Also, on a more advanced note, I've used https://github.com/ptaoussanis/timbre with great success to get nicely formatted and colored Clojure errors and stack traces.
(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))
(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).I'd be interested if anyone has some similar pieces to share.
With apps like Light Table now available, maybe beginners have an easier ramp these days.
Good luck go you!
Thank you.
[1] -- http://emacsformacosx.com
Good luck to you!
The fact that you don't have to use Emacs to work with Clojure is a huge benefit in my opinion. Emacs takes a lot of investment to learn and use effectively, and not everybody has the time, nor the inclination to do that.
There are a few typos, but the most glaring one was the incomplete python code underneath the "Code Structure" heading:
l = [1, 2, 3, 4, 5]
for i in l i = i*i
for i in l if (i mod 2 == 0)
print l
I assume the author wanted to show how the list was mutated. And those conditionals need trailing colons :)
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.https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...
https://cdn.rawgit.com/yogthos/yogthos.github.com/master/Clo...
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