Total Clojure

Table of Contents

1 Clojure : Practical Approach to Data Processing    slide title

1.1 Slides

1.1.1 Caution    slide

  • 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

1.1.2 What Data Science means ?    slide

"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    slide

go to Geneva now by train

1.1.4 Simple Example    slide

(go to Geneva now by train)

1.1.5 Simple Example    slide

(go to Geneva now by train)

(take (buy (first (train geneva))))

1.1.6 Simple Example    slide

(go to Geneva now by train)

(take (buy (first (train geneva))))

(take 
  (buy 
    (first 
      (train geneva))))

1.1.7 Simple Example    slide

(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    slide

  • 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    slide

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    slide

(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    slide

(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 ?    slide

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    slide

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    slide

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    slide

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    slide

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    slide

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    slide

  • Concepts : Values (ie something that doesn't change) Functions
  • Lambda Architecture presented in Big Data by Nathan Marz
  • 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    slide

  • Interop : all the best from java or javascript worlds

1.1.20 Clojure Books    slide

  • Dessert : Joy of Clojure by Fogus and Houser (2nd edition almost done)

1.1.21 Clojure Events    slide

  • Clojure sessions @ Soft-shake Oct 24-25 2013, Geneva CH
  • Clojure sessions @ FP Days Oct 24-25 2013, Cambridge UK

1.1.22 Speaker    slide

  • Maximilien Rzepka
  • Organizer of Clojure Zürich Meetup
  • @maxrzepka on twitter github …

1.1.23 References (1/3)    slide

(All the things I couln't put in my slides and possible tweets)

1.1.24 References (2/3)    slide

1.1.25 References (3/3)    slide

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

2 Footer

Date: 2013-10-24T08:09+0200

Author: Maximilien Rzepka

Org version 7.8.09 with Emacs version 24

Validate XHTML 1.0