thinking the clojure waygotocon.com/dl/goto-cph-2011/slides/christophegrand_introtothecl… ·...
TRANSCRIPT
![Page 1: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/1.jpg)
Thinking theClojure Way
Christophe Grand
GOTO Cph, May 13th 2011
![Page 2: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/2.jpg)
Rejoice, Clojure is simpleCoding along/againstSinging with
à la carte
![Page 3: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/3.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Coding along/againstSinging with
à la carte
![Page 4: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/4.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Coding along/againstSinging with
à la carte
![Page 5: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/5.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Simple means not compound
Coding along/againstSinging with
à la carte
![Page 6: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/6.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Simple means not compound
Clojure is made of simple things
Coding along/againstSinging with
à la carte
![Page 7: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/7.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Simple means not compound
Clojure is made of simple things
Small set of independent concepts
Coding along/againstSinging with
à la carte
![Page 8: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/8.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Simple means not compound
Clojure is made of simple things
Small set of independent concepts
One concept at a time
Coding along/againstSinging with
à la carte
![Page 9: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/9.jpg)
Rejoice, Clojure is simpleSmall regular syntax
Simple does not mean familiar
Simple means not compound
Clojure is made of simple things
Small set of independent concepts
One concept at a time
Coding along/againstSinging with
à la carte
![Page 10: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/10.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
State management
One bite at a timefaire 4 groupes :Syntax+FPRec+lazy seqspolymorphism+typesinterop+mutation
les deux derniers blocs devraient être animés pour être mis au même niveau
![Page 11: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/11.jpg)
Syntax
![Page 12: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/12.jpg)
LiteralsNumbers 42 3.14 3/4 5.01M 43N
Strings "Hello GOTO Cph"
Characters \c \newline
Keywords :a-key
Symbols foo clojure.core/map
Vectors [1 "two" :three]
Maps {:key "val", :key2 42}
Sets #{1 "two" :three}
Regex #"a.*b"
null nil
booleans* true false*anything but false and nil is true
![Page 13: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/13.jpg)
What about lists?
![Page 14: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/14.jpg)
What about lists?Quoted lists are too literal: '(1 (+ 1 1))
![Page 15: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/15.jpg)
What about lists?Quoted lists are too literal: '(1 (+ 1 1))
Displaced as literals by vectors
![Page 16: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/16.jpg)
What about lists?Quoted lists are too literal: '(1 (+ 1 1))
Displaced as literals by vectors
Abstracted away by sequences
![Page 17: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/17.jpg)
What about lists?Quoted lists are too literal: '(1 (+ 1 1))
Displaced as literals by vectors
Abstracted away by sequences
Survive mostly for code representation
![Page 18: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/18.jpg)
( defn abs [n] if neg? n) - n) n))
Lists are for code( ( (
![Page 19: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/19.jpg)
( defn abs [n] if neg? n) - n) n))
Lists are for code( ( (
Pro tip: Lisp code is a stereogram
![Page 20: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/20.jpg)
( defn abs [n] if neg? n) - n) n))
Lists are for code( ( (
Pro tip: Lisp code is a stereogramCross your eyes to see parens in the right place
![Page 21: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/21.jpg)
( defn abs [n] if neg? n) - n) n))
Lists are for code(
( (
Pro tip: Lisp code is a stereogramCross your eyes to see parens in the right place
![Page 22: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/22.jpg)
(defn abs [n] (if (neg? n) (- n) n))
Lists are for code
![Page 23: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/23.jpg)
(defn abs [n] (if (neg? n) (- n) n))
Lists are for code
function
![Page 24: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/24.jpg)
(defn abs [n] (if (neg? n) (- n) n))
Lists are for code
macro
function
![Page 25: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/25.jpg)
(defn abs [n] (if (neg? n) (- n) n))
Lists are for code
special form
macro
function
![Page 26: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/26.jpg)
That’s all about syntax!
![Page 27: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/27.jpg)
Functional Programming
![Page 28: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/28.jpg)
Clojure’s FP
![Page 29: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/29.jpg)
Clojure’s FPImpure
![Page 30: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/30.jpg)
Clojure’s FPImpure
Persistent collections
![Page 31: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/31.jpg)
Clojure’s FPImpure
Persistent collections
Strictly evaluated
![Page 32: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/32.jpg)
Clojure’s FPImpure
Persistent collections
Strictly evaluated
But lazy sequences
![Page 33: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/33.jpg)
Clojure’s FPImpure
Persistent collections
Strictly evaluated
But lazy sequences
Not strictly lazy though!
![Page 34: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/34.jpg)
Clojure’s FPImpure
Persistent collections
Strictly evaluated
But lazy sequences
Not strictly lazy though!
![Page 35: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/35.jpg)
Persistent collections
![Page 36: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/36.jpg)
Persistent collectionsVectors, maps and sets
![Page 37: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/37.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
![Page 38: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/38.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
Vectors as tuples
![Page 39: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/39.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
Vectors as tuples
Vectors as stacks
![Page 40: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/40.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
Vectors as tuples
Vectors as stacks
Maps as data
![Page 41: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/41.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
Vectors as tuples
Vectors as stacks
Maps as data
Map as index, summary
![Page 42: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/42.jpg)
Persistent collectionsVectors, maps and sets
Common usecases:
Vectors as tuples
Vectors as stacks
Maps as data
Map as index, summary
Sets as containers, relations
![Page 43: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/43.jpg)
Sequences
![Page 44: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/44.jpg)
SequencesFirst, what are sequences?
![Page 45: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/45.jpg)
SequencesFirst, what are sequences?
Abstraction over linked lists
![Page 46: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/46.jpg)
SequencesFirst, what are sequences?
Abstraction over linked lists
List-like views over data
![Page 47: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/47.jpg)
SequencesFirst, what are sequences?
Abstraction over linked lists
List-like views over data
Support first and rest
![Page 48: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/48.jpg)
SequencesFirst, what are sequences?
Abstraction over linked lists
List-like views over data
Support first and rest
Replace iterators
![Page 49: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/49.jpg)
SequencesFirst, what are sequences?
Abstraction over linked lists
List-like views over data
Support first and rest
Replace iterators
Replace indices
![Page 50: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/50.jpg)
Lazy sequences
![Page 51: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/51.jpg)
Lazy sequencesSequences evaluated (realized) on demand
![Page 52: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/52.jpg)
Lazy sequencesSequences evaluated (realized) on demand
Allow to process big data
![Page 53: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/53.jpg)
Lazy sequencesSequences evaluated (realized) on demand
Allow to process big data
or big intermediate values
![Page 54: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/54.jpg)
Lazy sequencesSequences evaluated (realized) on demand
Allow to process big data
or big intermediate values
(->> (slurp "access.log") split-lines (map count) (filter odd?))
![Page 55: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/55.jpg)
Lazy sequences
Doesn’t matter w/ strict evaluation
![Page 56: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/56.jpg)
Lazy sequencesRealization can go ahead of consumption
Doesn’t matter w/ strict evaluation
![Page 57: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/57.jpg)
Lazy sequencesRealization can go ahead of consumption
Not suitable for control flow Doesn’t matter w/ strict evaluation
![Page 58: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/58.jpg)
Lazy sequencesRealization can go ahead of consumption
Not suitable for control flow
Better locality, less churn
Doesn’t matter w/ strict evaluation
![Page 59: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/59.jpg)
That’s all about FP!
![Page 60: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/60.jpg)
Clojure spirit
![Page 61: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/61.jpg)
Clojure spirit
![Page 62: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/62.jpg)
Clojure spiritPragmatism
![Page 63: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/63.jpg)
Clojure spiritPragmatism
Correctness
![Page 64: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/64.jpg)
Clojure spiritPragmatism
Correctness
Uniform interfaces
![Page 65: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/65.jpg)
Clojure spiritPragmatism
Correctness
Uniform interfaces
Data over functions
![Page 66: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/66.jpg)
Clojure spiritPragmatism
Correctness
Uniform interfaces
Data over functions
Sequences as computation media
![Page 67: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/67.jpg)
Clojure spiritPragmatism
Correctness
Uniform interfaces
Data over functions
Sequences as computation media
Reftypes as mutation patterns
![Page 68: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/68.jpg)
PragmatismHosted on the JVM
Embrace the host limitations
to be a better guest
Excellent Java interop
Performance over purity
LISP
![Page 69: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/69.jpg)
CorrectnessNo silent error
Correct result or failure
Non-negotiable
See 1.2 -> 1.3 numerics changes
Unless the user opts in
![Page 70: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/70.jpg)
Uniform interfaces
![Page 71: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/71.jpg)
Uniform interfacesWidespread small interfaces
![Page 72: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/72.jpg)
Uniform interfacesWidespread small interfaces
Tons of helpers fns built upon
![Page 73: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/73.jpg)
Uniform interfacesWidespread small interfaces
Tons of helpers fns built upon
It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.
– Alan Perlis
![Page 74: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/74.jpg)
Uniform interfacesWidespread small interfaces
Tons of helpers fns built upon
It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.
– Alan PerlisIt is better to have 100 functions operate on one abstraction than 10 functions on 10 data structures.
– Rich Hickey
![Page 75: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/75.jpg)
Uniform interfaces
=> (-> (javax.swing.JFrame.) bean keys sort)(:JMenuBar :accessibleContext :active :alignmentX :alignmentY :alwaysOnTop :alwaysOnTopSupported :background :bufferStrategy :componentCount :components :containerListeners :contentPane :cursorType :defaultCloseOperation ...)
=> (-> {:product-id "ACME123", :description "Powder water"} keys sort)(:description :product-id)
![Page 76: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/76.jpg)
Data over functionsLarge reuse of core collection fns
Less specific code
Data go out of the process
Don’t be too clever
A schema is a good API
![Page 77: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/77.jpg)
Data over functions
![Page 78: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/78.jpg)
Data over functionsHow to enforce invariants
![Page 79: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/79.jpg)
Data over functionsHow to enforce invariants
Write a validator function
![Page 80: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/80.jpg)
Data over functionsHow to enforce invariants
Write a validator function
Use it in fns pre- and post-conditions
![Page 81: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/81.jpg)
Data over functionsHow to enforce invariants
Write a validator function
Use it in fns pre- and post-conditions
Use it in reftypes validators
![Page 82: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/82.jpg)
Sequences as pipes
![Page 83: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/83.jpg)
Sequences as pipesSequences as ephemeral media of computation
![Page 84: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/84.jpg)
Sequences as pipesSequences as ephemeral media of computation
Each stage of a pipeline yields its own seq
![Page 85: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/85.jpg)
Sequences as pipesSequences as ephemeral media of computation
Each stage of a pipeline yields its own seq
The ends of the pipeline are not seqs:
![Page 86: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/86.jpg)
Sequences as pipesSequences as ephemeral media of computation
Each stage of a pipeline yields its own seq
The ends of the pipeline are not seqs:
db, network, persistent collection etc.
![Page 87: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/87.jpg)
Sequences as pipesSequences as ephemeral media of computation
Each stage of a pipeline yields its own seq
The ends of the pipeline are not seqs:
db, network, persistent collection etc.
![Page 88: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/88.jpg)
Mutation patterns
![Page 89: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/89.jpg)
Mutation patternsReftypes embody mutation patterns
![Page 90: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/90.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
![Page 91: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/91.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
Refs, atoms and agents
![Page 92: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/92.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
Refs, atoms and agents
Program state management:
![Page 93: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/93.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
Refs, atoms and agents
Program state management:
Vars
![Page 94: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/94.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
Refs, atoms and agents
Program state management:
Vars
Execution or dataflow management:
![Page 95: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/95.jpg)
Mutation patternsReftypes embody mutation patterns
Application state management:
Refs, atoms and agents
Program state management:
Vars
Execution or dataflow management:
Promises, delays and futures
![Page 96: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/96.jpg)
How to think functionally?
![Page 97: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/97.jpg)
Break your habits
![Page 98: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/98.jpg)
Tie your imperative hand behind your back!
![Page 99: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/99.jpg)
Tie your OO hand too!
![Page 100: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/100.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 101: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/101.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 102: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/102.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 103: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/103.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 104: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/104.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 105: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/105.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 106: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/106.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 107: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/107.jpg)
Syntax
Core Functional Programming
Recursion and loops
Lazy seqs (creating your owns)
Polymorphism
Types
Macros
Interop
Mutation
Features
![Page 108: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/108.jpg)
Pure Functional Programming
without recursion nor loops
without lazy-seq
without indices
Allowed subset
![Page 109: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/109.jpg)
Do it until it hurts!(and works)
![Page 110: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/110.jpg)
Do it especially for ill-suited problems!
![Page 111: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/111.jpg)
Example:Conway’s game of life
![Page 112: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/112.jpg)
RulesAt each step in time, the following transitions occur:
• Any live cell with fewer than two live neighbours dies, as if caused by under-population.
• Any live cell with two or three live neighbours lives on to the next generation.
• Any live cell with more than three live neighbours dies, as if by overcrowding.
• Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
(wikipedia)
![Page 113: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/113.jpg)
(defn step "Takes a vector of vectors of 0 and 1, and returns the next iteration of the automaton." [board] (let [w (count board) h (count (first board))] (loop [i 0 j 0 new-board board] (cond (>= i w) new-board (>= j h) (recur (inc i) 0 new-board) :else (let [n (neighbours-count board i j) nb (cond (= 3 n) (assoc-in new-board [i j] 1) (not= 2 n) (assoc-in new-board [i j] 0) :else new-board)] (recur i (inc j) new-board))))))
Conway’s game of lifeTypical implementation is full of indices and loops
![Page 114: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/114.jpg)
(defn step "Takes a vector of vectors of 0 and 1, and returns the next iteration of the automaton." [board] (let [w (count board) h (count (first board))] (loop [i 0 j 0 new-board board] (cond (>= i w) new-board (>= j h) (recur (inc i) 0 new-board) :else (let [n (neighbours-count board i j) nb (cond (= 3 n) (assoc-in new-board [i j] 1) (not= 2 n) (assoc-in new-board [i j] 0) :else new-board)] (recur i (inc j) new-board))))))
Conway’s game of lifeTypical implementation is full of indices and loops
![Page 115: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/115.jpg)
(defn neighbours-count [board i j] (let [i+1 (inc i) j+1 (inc j)] (loop [cnt 0 x (dec i) y (dec j)] (cond (> x i+1) cnt (> y j+1) (recur cnt (inc x) (dec j)) (= [x y] [i j]) (recur cnt x (inc y)) :else (recur (+ cnt (get-in board [x y] 0)) x (inc y))))))
Conway’s game of lifeAnd there’s more!
![Page 116: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/116.jpg)
(defn neighbours-count [board i j] (let [i+1 (inc i) j+1 (inc j)] (loop [cnt 0 x (dec i) y (dec j)] (cond (> x i+1) cnt (> y j+1) (recur cnt (inc x) (dec j)) (= [x y] [i j]) (recur cnt x (inc y)) :else (recur (+ cnt (get-in board [x y] 0)) x (inc y))))))
Conway’s game of lifeAnd there’s more!
![Page 117: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/117.jpg)
Look, no indicesAt each step in time, the following transitions occur:
• Any live cell with fewer than two live neighbours dies, as if caused by under-population.
• Any live cell with two or three live neighbours lives on to the next generation.
• Any live cell with more than three live neighbours dies, as if by overcrowding.
• Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
(wikipedia)
![Page 118: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/118.jpg)
Take a step back!
![Page 119: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/119.jpg)
Look, no indicesAt each step in time, the following transitions occur:
• Any live cell with fewer than two live neighbours dies, as if caused by under-population.
• Any live cell with two or three live neighbours lives on to the next generation.
• Any live cell with more than three live neighbours dies, as if by overcrowding.
• Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
(wikipedia)
![Page 120: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/120.jpg)
Neighbours!
![Page 121: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/121.jpg)
Neighbours!Try to express the rules in code using the neighbours concept
![Page 122: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/122.jpg)
Neighbours!Try to express the rules in code using the neighbours concept
Don’t worry about the implementation of neighbours
![Page 123: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/123.jpg)
Neighbours!
![Page 124: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/124.jpg)
Neighbours!For each living cell or neighbour of a living cell, compute the number of neighbours.
![Page 125: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/125.jpg)
Neighbours!For each living cell or neighbour of a living cell, compute the number of neighbours.
Then apply generation rules.
![Page 126: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/126.jpg)
Neighbours!
![Page 127: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/127.jpg)
Neighbours!Compute all neighbours of the living cells.
![Page 128: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/128.jpg)
Neighbours!Compute all neighbours of the living cells.
Occurences count is neighbour count!
![Page 129: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/129.jpg)
Neighbours!Compute all neighbours of the living cells.
Occurences count is neighbour count!
Then apply generation rules.
![Page 130: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/130.jpg)
(defn step "Takes a set of living cells and returns the next generation (as a set too)." [living-cells] (letfn [(alive [[cell cnt]] (when (or (= cnt 3) (and (= cnt 2) (living-cells cell))) cell))] (->> living-cells (mapcat neighbours) frequencies (keep alive) set)))
Neighbours!
![Page 131: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/131.jpg)
(defn step "Takes a set of living cells and returns the next generation (as a set too)." [living-cells] (letfn [(alive [[cell cnt]] (when (or (= cnt 3) (and (= cnt 2) (living-cells cell))) cell))] (->> living-cells (mapcat neighbours) frequencies (keep alive) set)))
Neighbours!
![Page 132: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/132.jpg)
(defn step "Takes a set of living cells and returns the next generation (as a set too)." [living-cells] (letfn [(alive [[cell cnt]] (when (or (= cnt 3) (and (= cnt 2) (living-cells cell))) cell))] (->> living-cells (mapcat neighbours) frequencies (keep alive) set)))
Neighbours!(defn neighbours [[x y]] (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])] [(+ x dx) (+ y dy)]))
![Page 133: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/133.jpg)
Drafting code
![Page 134: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/134.jpg)
Drafting codeDon’t go to the details
![Page 135: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/135.jpg)
Drafting codeDon’t go to the details
Draft high-level code you’d like to be able to write to solve the problem
![Page 136: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/136.jpg)
Drafting codeDon’t go to the details
Draft high-level code you’d like to be able to write to solve the problem
Try to implement it
![Page 137: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/137.jpg)
Drafting codeDon’t go to the details
Draft high-level code you’d like to be able to write to solve the problem
Try to implement it
Negociate between practicality of implementation and draft code
![Page 138: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/138.jpg)
But it really hurts...
![Page 139: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/139.jpg)
But it really hurts...Ask for help
![Page 140: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/140.jpg)
But it really hurts...Ask for help
#clojure on IRC
![Page 141: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/141.jpg)
But it really hurts...Ask for help
#clojure on IRC
Stackoverflow
![Page 142: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/142.jpg)
But it really hurts...Ask for help
#clojure on IRC
Stackoverflow
clojure google group
![Page 143: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/143.jpg)
But it really hurts...Ask for help
#clojure on IRC
Stackoverflow
clojure google group
reach your local user group
![Page 144: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/144.jpg)
But it really hurts...Ask for help
#clojure on IRC
Stackoverflow
clojure google group
reach your local user group
create your local user group
![Page 145: Thinking the Clojure Waygotocon.com/dl/goto-cph-2011/slides/ChristopheGrand_IntroToTheCl… · Thinking the Clojure Way Christophe Grand GOTO Cph, May 13th 2011. Rejoice, Clojure](https://reader035.vdocuments.us/reader035/viewer/2022062311/5fe93eab41cda430c35d7010/html5/thumbnails/145.jpg)
But it really hurts...Ask for help
#clojure on IRC
Stackoverflow
clojure google group
reach your local user group
create your local user group
mail me [email protected]