Installation:
- Setting up Clojure on OS X
- Setup notes from Nilenso Clojure workshop (includes editor setup)
- Screencast: Clojure+Vim Basics
brew install leiningen
lein repl
Example code:
(ref: Stuart Holloway: Introduction to Clojure)
(println "Hello, world")
(defn hello
"Returns a greeting"
[name]
(str "Hello, " name))
;; vectors
(def v [42 :rabbit [1 2 3]])
(v 1) -> :rabbit
(peek v) -> [1 2 3]
(pop v) -> [42 :rabbit]
(subvec 1) -> [:rabbit [1 2 3]]
;; maps
(def m { :a 1 :b 2 :c 3 })
(m :b) -> 2
(:b m) -> 2
(keys m) -> (:a :b :c)
(assoc m :d 4 :c 42) -> {:d 4, :a 1, :b 2, :c 42}
(dissoc m :d) -> {:a 1 :b 2, :c 42}
(merge-with + m {:a 2 :b 3}) -> {:a 3 :b 5 :c 42}
(def user {:name "John Doe"
:address {:zip 123456}})
(get-in user [:address :zip])
(assoc-in user [:address :zip] 123567)
-> {:name "John Doe", :address {:zip 123567}}
Clojure related bookmarks:
- Try Clojure - browser based REPL
- Grimoire - Community Clojure Documentation
- The Clojure Toolbox - A categorised directory of libraries and tools for Clojure
- Clojure Styleguide by @bbatsov
- Clojure Koans
- 4Clojure - interactive problems similar to Project Euler
Books and tutorials
- Clojure for the Brave and True - beginner level Clojure book
- Clojure From the Ground Up
- Clojure Distilled
Videos:
Emacs integration