This document provides an overview of the Clojure programming language and its key features. It discusses Clojure's dynamic and functional nature, its use of immutable data and state management via atoms, refs, and agents. It also covers Clojure's interactive development environment via the REPL, its treatment of code as data, and how functions and macros are defined. Examples are provided of Clojure code for Conway's Game of Life.
2. Clojure
• A Lisp on the JVM (also ClojureScript on JavaScript)
• Dynamic (types, code, etc)
• Functional language
• Compiled (there is no interpreter)
• Immutability and state management
• Code is data
• REPL - Read / Eval / Print / Loop
• Interactive development
2
3. It looks like this...
(defn neighbors [[x y]]
(for [dx [-1 0 1]
dy (if (zero? dx)
[-1 1]
[-1 0 1])]
[(+ dx x) (+ dy y)]))
(defn live [n alive?]
(or (= n 3)
(and (= n 2) alive?)))
(defn step [world]
(set
(for [[cell n] (frequencies (mapcat neighbors world))
:when (live n (world cell))]
cell)))
(defn life [initial-world]
(iterate step initial-world))
3
70. Conway's Life
Life's rules:
If alive and 2 or 3 neighbors Then stay alive Else die
If dead and 3 neighbors Then come to life
"Blinker" configuration
Implementation courtesy of Christophe Grand
http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/
41
71.
72.
73. Thanks!
• Twitter: @puredanger
• Blog: http://tech.puredanger.com
• Work: http://revelytix.com
• My conferences
– Strange Loop - http://thestrangeloop.com
– Clojure/West - http://clojurewest.com
If you want to pair on Clojure during
Devoxx, ping me on Twitter!
43