Maybe you've heard of Clojure, one of those new-fangled JVM languages. How does anybody get any work done in a language like that? What's up with all those parentheses? If you're coming from Java and OOP, Clojure can indeed feel disorienting. In this talk we'll demystify the basics of Clojure and dissect the source of its power. Functional programming is on the rise and Clojure is indeed a functional language, but we'll learn the real secret sauce that makes cooking with Clojure fun. We'll look at how to translate concepts you know in Java (like domain objects, interfaces, collections, and concurrency) into their natural Clojure equivalents. And more importantly, we'll learn how these components interact to make Clojure a beautiful language for building abstractions. No prior knowledge of Clojure or functional programming is assumed... Clojure novices welcome!
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
Conways Life Lifes rules: If alive and 2 or 3 neighbors Then stay alive Else die If dead and 3 neighbors Then come to life "Blinker" conﬁguration Implementation courtesy of Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/ 41
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