Total Clojure
Table of Contents
- 1 Clojure : Practical Approach to Data Processing
- 1.1 Slides
- 1.1.1 Caution
- 1.1.2 What Data Science means ?
- 1.1.3 Simple Example
- 1.1.4 Simple Example
- 1.1.5 Simple Example
- 1.1.6 Simple Example
- 1.1.7 Simple Example
- 1.1.8 LISt Processing
- 1.1.9 Let's practice : Bowling Scorer
- 1.1.10 Bowling Scorer I
- 1.1.11 Bowling Scorer II
- 1.1.12 Where are my indices ?
- 1.1.13 Declarative Way I Enlive
- 1.1.14 Declarative Way II Cascalog
- 1.1.15 Visual Comparison
- 1.1.16 Declarative Way III Moustache
- 1.1.17 Declarative Way IV core.logic
- 1.1.18 New Art of Processing Data
- 1.1.19 Clojure Landscape
- 1.1.20 Clojure Books
- 1.1.21 Clojure Events
- 1.1.22 Speaker
- 1.1.23 References (1/3)
- 1.1.24 References (2/3)
- 1.1.25 References (3/3)
- 1.1 Slides
- 2 Footer
1 Clojure : Practical Approach to Data Processing title
1.1 Slides
1.1.1 Caution
- My personal take on what means programming : Science or Art ?
- "Make you Think" style rather than "Show you How To do" style
- Keep questioning your knowledge
- I don't know what I'm doing - Bret Victor
1.1.2 What Data Science means ?
"Data Science incorporates various fields … with the goal of extracting meaning from data and creating data products." from Wikipedia
- Data Science = Art of Processing Data
- Ordinateur = Receive / Store / Process / Emit Information
- Computer Science < Science of Information (Informatique in French)
- Information Technology
1.1.3 Simple Example
go to Geneva now by train
1.1.4 Simple Example
(go to Geneva now by train)
1.1.5 Simple Example
(go to Geneva now by train)
(take (buy (first (train geneva))))
1.1.6 Simple Example
(go to Geneva now by train)
(take (buy (first (train geneva))))
(take (buy (first (train geneva))))
1.1.7 Simple Example
(go to Geneva now by train)
(take (buy (first (train geneva))))
(take (buy (first (train geneva))))
(-> geneva train first buy take)
1.1.8 LISt Processing
- Simple syntax reveals the shape of your program
- Abstract syntax independant of how machines work
- List Driven Development : The world is a set of connected lists
My presentation is a list of lists with links to the WWW.
- Flexibility to create new abstractions
- Ready to approach real-world complexity
1.1.9 Let's practice : Bowling Scorer
Roll : nb of pins knocked down (2 3 0 0 10 9 1 5 0) Frame : rolls (max. of 2) to knock down 10 pins ((2 3) (0 0) (10) (9 1) (5 0)) "scored" Frames ((2 3) (0 0) (10 9 1) (9 1 5) (5 0))
- An implementation in Java as XP episode and thread discussing clojure solution.
1.1.10 Bowling Scorer I
(defn frames [rolls] (cons (take (balls-to-score rolls) rolls) (frames (drop (frame-advance rolls) rolls)))) (defn score [frames] (reduce + (map (partial reduce +) frames)))
1.1.11 Bowling Scorer II
(defn strike? [rolls] (= 10 (first rolls))) (defn spare? [rolls] (and (= 10 (apply + (take 2 rolls))) (> 10 (first rolls)))) (defn balls-to-score [rolls] (cond (strike? rolls) 3 (spare? rolls) 3 :else 2)) (defn frame-advance [rolls] (if (strike? rolls) 1 2))
1.1.12 Where are my indices ?
Using Sequence Abstraction helps to build better program … without indices. Perfect example is Game of Life written by Christophe Grand in Clojure Programming Chapter 3
(defn step [cells] (set (for [[loc n] (frequencies (mapcat neighbours cells)) :when (or (= n 3) (and (= n 2) (cells loc)))] loc))) (defn neighbours [[x y]] (for [dx [-1 0 1] dy [-1 0 1] :when (not= 0 dx dy)] [(+ dx x) (+ dy y)]))
1.1.13 Declarative Way I Enlive
Select and transform Tree-Data (HTML). Scraping and Templating are use cases among others.
[:li :a] [:li [:a (attr= :class "special")]]
Outter [] means inclusion, Inner [] means conjunction
<div> <ul> <li><a class="special">ll1</a></li> <li><a href="/">index</a></li> </ul> </div>
1.1.14 Declarative Way II Cascalog
Query Language for Hadoop MapReduce
(<- [?word ?count] (my-source ?text) (split ?text :> ?word) (c/count ?count)) (defmapcatop split [text] (seq (.split text #"\\s+")))
1.1.15 Visual Comparison
Scalding : cascalog sibling in scala.
TextLine("inFile") .flatMap { l => l.split("\\s+").map((_, 1L)) } .sumByKey .write(TypedTsv[(String,Long)]("outFile"))
Less declarative more focused on how to do things.
More details in Paco Nathan's latest book Enterprise Data Workflows with Cascading
1.1.16 Declarative Way III Moustache
Define the routes of a web application.
(app ["my" "long" "uri"] view-it ["order" [id integer]] {:get view-order :post change-order})
1.1.17 Declarative Way IV core.logic
Logic Programming in clojure
(run [q] (appendo [1 2] q [1 2 3 4 5]))
gives an unique solution [3 4 5]
Constaints on data structures , on finite domains to resolve linear equations…
1.1.18 New Art of Processing Data
- Concepts : Values (ie something that doesn't change) Functions
- Lambda Architecture presented in Big Data by Nathan Marz
- Human-Fault-Tolerance System
- Always append Never delete
- A Query is a function over all the data
- Functional Database : datomic created by Rich Hickey
- Database as Value
- Fact = datom = Entity/Attribute/Value/Transaction (E/A/V/Tx)
1.1.19 Clojure Landscape
- NewData : datomic storm cascalog Lambda architecture
- Web : ring edn clojurescript
- Logic/Constraint Programming : core.logic
- Concurrency & co : atom STM core.async
- Type System : core.typed schema
- Interop : all the best from java or javascript worlds
- And Much More : incanter core.matrix core.match CinC…
1.1.20 Clojure Books
- Starter : Programming Clojure by Halloway and Bedra
- Main : Clojure Programming by Carper, Emerick and Grand
- Dessert : Joy of Clojure by Fogus and Houser (2nd edition almost done)
- In-Progress : Clojure Cookbook collected by VanderHart and Neufeld
1.1.21 Clojure Events
- Euro Clojure 14-15 Oct. 2013, Berlin DE
- Clojure sessions @ Soft-shake Oct 24-25 2013, Geneva CH
- Clojure sessions @ FP Days Oct 24-25 2013, Cambridge UK
- Clojure Conj Nov 14-16 2013, Washington DC US
- Clojure Exchange Dec 06 2013, London UK
- Training in Europe with lambda-next and clojure workshop
1.1.22 Speaker
- Maximilien Rzepka
- Organizer of Clojure Zürich Meetup
- @maxrzepka on twitter github …
1.1.23 References (1/3)
(All the things I couln't put in my slides and possible tweets)
- Lecture 1a: Overview and Introduction to Lisp by Hal Abelson : Art/Engineer of Processes
- Introduction to Systematic Program Design by Gregor Kiczales : How to design program with racket (another LISP dialect)
- Computer = Receive / Store / Treat / Emit Information in Conférence de Michel Serres
- About Information Technologies in Value of Values by Rich Hickey
- Fehler sind wie Berge, man steht auf dem Gipfel seiner eigenen und redet über die der anderen. Sprichwort der Hausa
1.1.24 References (2/3)
- OO vs FP , nouns vs verbs is a wrong debate cf La structure des langues by Claude Hagège page 69
- English like german are satellite-framed languages (I talked myself out of a job / I talked myself into a job) page 160
- English is about facts French is about understanding in Against Uniform Thinking by Claude Hagège Chapter 5
- However many languages you know, that much of a human you are. - Armenian proverb
- Gérard Berry Algorithmes, machines et langages from Collège De France
1.1.25 References (3/3)
The list is the origin of culture. It’s part of the history of art and literature. What does culture want? To make infinity comprehensible… And how, as a human being, does one face infinity? How does one attempt to grasp the incomprehensible? Through lists…
Umberto Eco from The Origin of The Todo list… by Buffer
- Communication (fr) by Michel Serres on univeral machines : receive/store/process/emit information.
- Human-Fault-Tolerance - Nathan Marz
- cons/conj explained by Michal Marczyk