SlideShare une entreprise Scribd logo
1  sur  22
Introduction à
    Clojure




  Pablo Tamarit
 30 octobre 2012
   Geneva JUG
1999 - 2005                                       2007 - 2049
                 EIG                                               CERN
2000   2001   2002   2003   2004   2005   2006   2007   2008   2009   2010   2011   2012




                                          ?
Avant-goût
 (def panier [{:nom "pommes",     :type :fruits}
              {:nom "poires",     :type :fruits}
              {:nom "scoubidous", :type :objets}])



 (group-by :type panier)



 {:fruits [{:type :fruits, :nom "pommes"}
           {:type :fruits, :nom "poires"}],
  :objets [{:type :objets, :nom "scoubidous"}]}
• Partie philosophique

• Partie théorique

• Partie pratique
Partie philosophique
Clojure

                                + λ
•   Créé en 2007           •   Tout est immutable
•   Simplicité             •   Pas d'état
•   Pas d’orienté objet!   •   Pas d'effets de bord
•   Typage dynamique       •   Dialecte de Lisp!
Lisp
• Inventé en 1958
John McCarthy
  1927 – 2011
Lisp
• Inventé en 1958
• Lots of
  Irritating
  Superfluous
  Parentheses?
Lisp
• Inventé en 1958     • Homoiconicité
• Lots of             • Macros
  Irritating
  Superfluous
  Parentheses


        paulgraham.com/avg.html
Partie théorique
Langage

• Syntaxe simple, vocabulaire riche.

  – Syntaxe: données, fonctions

  – Vocabulaire: fonctions

                             clojure.org/cheatsheet
Syntaxe: collections
Liste                    ("un" 2 3 3)
Vecteur                  ["un" 2 3 3]
Set                      #{"un" 2 3}
Map                      {:nom "Pablo", :age 28}




          (:age {:nom "Pablo", :age 28})

                       28
Syntaxe: fonctions
                             fn           args
                     liste                                   vecteur
Appel                             (+ 1 2 3)
Définition                        (defn abs [n]
                                    (if (neg? n)           condition
                                      (- n)                then
                                      n))                  else
Définition anonyme                (fn [x y] (+ (abs x) (abs y)))
Définition anonyme sucrée         #(+ (abs %1) (abs %2))
Vocabulaire: fonctions
(def coll [-42 5 -0.1])

(map abs coll)
 (42 5 0.1)

(reduce + 0 coll)
 -37.1

(filter neg? coll)
 (-42 -0.1)
Interop
                   Java                            Clojure
    new JFrame("Titre")              (JFrame. "Titre")
    Color.RED                        Color/RED
    frame.setTitle("Titre2")         (.setTitle frame "Titre2")
4   frame.getTitle().toLowerCase()   (.. frame getTitle toLowerCase)   2
3   frame.add(panel)                 (doto frame                       1
    frame.pack()                       (.add panel)
    frame.setVisible(true)             (.pack)
                                       (.setVisible true))
Partie pratique
Quoi installer?
• Rien!
  <dependency>
    <groupId>org.clojure</groupId>
    <artifactId>clojure</artifactId>
    <version>1.4.0</version>
  </dependency>

• Qui a-t-il dans le JAR?
  – La librairie
  – REPL: java -jar clojure.jar
  – Compilateur: .clj  .class
Outils
• Build
  – leiningen
  – clojure-maven-plugin


• IDE
  – Counterclockwise (Eclipse)
  – La Clojure (IntelliJ IDEA)
  – Emacs!
Apprentissage
• Présentations:
  – blip.tv/clojure
  – infoq.com/clojure

• Livres:
  – clojurebook.com
  – joyofclojure.com

• Exercices:
  – 4clojure.com
Questions?
Crédits graphiques
• Logo Clojure: © Tom Hickey (tomhickey.com)
• Vue aérienne du LHC: © 2001 CERN
  (cdsweb.cern.ch/record/42370)
• La Trahison des images: © 1929 René Magritte
• Duke models: © Sun Microsystems Inc. (duke.kenai.com/models)
• Portrait de John McCarthy: © 2006 null0 (flic.kr/p/q39Sg)
• L'Appel des cimes: © 1942 René Magritte
• La Clairvoyance: © 1936 René Magritte
• Cooled Beans: © 2008 Chris Bay (flic.kr/p/4z6CBA)
• Gears: © Dima Yagnyuk (thenounproject.com/noun/gears/#icon-
  No2174, thenounproject.com/Deadtype)
• Tools: © Jacob Hardbower (thenounproject.com/noun/tools/#icon-
  No4684, thenounproject.com/HeartWired)

Contenu connexe

Tendances

Mort au boilerplate avec scala meta
Mort au boilerplate avec scala metaMort au boilerplate avec scala meta
Mort au boilerplate avec scala metaDamien GOUYETTE
 
Les nouveautés de java 7 et les promesses
Les nouveautés de java 7  et les promessesLes nouveautés de java 7  et les promesses
Les nouveautés de java 7 et les promessesEric Toguem
 
Programmation fonctionnelle
Programmation fonctionnelleProgrammation fonctionnelle
Programmation fonctionnelleGeeks Anonymes
 
Meetup pg recherche fulltext ES -> PG
Meetup pg recherche fulltext ES -> PGMeetup pg recherche fulltext ES -> PG
Meetup pg recherche fulltext ES -> PGLouise Grandjonc
 
JDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJosé Paumard
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaCh'ti JUG
 
Theme 9(bis)
Theme 9(bis)Theme 9(bis)
Theme 9(bis)salmazen
 
Android Optimisations Greendroid
Android Optimisations GreendroidAndroid Optimisations Greendroid
Android Optimisations GreendroidGDG Nantes
 
Librairies Java qui changent la vie
Librairies Java qui changent la vieLibrairies Java qui changent la vie
Librairies Java qui changent la viecluelessjoe
 
Chapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaChapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaAziz Darouichi
 
Formation python micro club.net
Formation python micro club.netFormation python micro club.net
Formation python micro club.netZakaria SMAHI
 
Fest assert - Rendez vos assertions lisibles
Fest assert - Rendez vos assertions lisiblesFest assert - Rendez vos assertions lisibles
Fest assert - Rendez vos assertions lisiblesNicolas FRANCOIS
 
Introduction à la programmation
Introduction à la programmationIntroduction à la programmation
Introduction à la programmationpierrepo
 
Introduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniIntroduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniShellmates
 
Asyncio: offrez des tulipes à vos entrées sorties asynchrones
Asyncio: offrez des tulipes à vos entrées sorties asynchronesAsyncio: offrez des tulipes à vos entrées sorties asynchrones
Asyncio: offrez des tulipes à vos entrées sorties asynchronestchappui
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Guillaume Laforge
 

Tendances (20)

Mort au boilerplate avec scala meta
Mort au boilerplate avec scala metaMort au boilerplate avec scala meta
Mort au boilerplate avec scala meta
 
Les nouveautés de java 7 et les promesses
Les nouveautés de java 7  et les promessesLes nouveautés de java 7  et les promesses
Les nouveautés de java 7 et les promesses
 
Programmation fonctionnelle
Programmation fonctionnelleProgrammation fonctionnelle
Programmation fonctionnelle
 
Meetup pg recherche fulltext ES -> PG
Meetup pg recherche fulltext ES -> PGMeetup pg recherche fulltext ES -> PG
Meetup pg recherche fulltext ES -> PG
 
JDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne Tour
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambda
 
Theme 9(bis)
Theme 9(bis)Theme 9(bis)
Theme 9(bis)
 
Android Optimisations Greendroid
Android Optimisations GreendroidAndroid Optimisations Greendroid
Android Optimisations Greendroid
 
Programmation Fonctionnelle
Programmation FonctionnelleProgrammation Fonctionnelle
Programmation Fonctionnelle
 
Librairies Java qui changent la vie
Librairies Java qui changent la vieLibrairies Java qui changent la vie
Librairies Java qui changent la vie
 
Change mind about JS
Change mind about JSChange mind about JS
Change mind about JS
 
Chapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaChapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En Java
 
Formation python micro club.net
Formation python micro club.netFormation python micro club.net
Formation python micro club.net
 
Implementing a key/value store
Implementing a key/value storeImplementing a key/value store
Implementing a key/value store
 
Fest assert - Rendez vos assertions lisibles
Fest assert - Rendez vos assertions lisiblesFest assert - Rendez vos assertions lisibles
Fest assert - Rendez vos assertions lisibles
 
Introduction à la programmation
Introduction à la programmationIntroduction à la programmation
Introduction à la programmation
 
Introduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniIntroduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El Hassani
 
Asyncio: offrez des tulipes à vos entrées sorties asynchrones
Asyncio: offrez des tulipes à vos entrées sorties asynchronesAsyncio: offrez des tulipes à vos entrées sorties asynchrones
Asyncio: offrez des tulipes à vos entrées sorties asynchrones
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013
 
Ruby Pour RoR
Ruby Pour RoRRuby Pour RoR
Ruby Pour RoR
 

En vedette

Parasympathethic system
Parasympathethic systemParasympathethic system
Parasympathethic systemanasvv
 
Narrativa gráfica-Ofelia Romero
Narrativa gráfica-Ofelia RomeroNarrativa gráfica-Ofelia Romero
Narrativa gráfica-Ofelia RomeroOfelia Romero
 
Present simple
Present simplePresent simple
Present simpleManuSan91
 
Plessy vs ferguson
Plessy vs fergusonPlessy vs ferguson
Plessy vs fergusonKeri Hays
 
Grammar book 3
Grammar book 3Grammar book 3
Grammar book 3amecia411
 
How to succeed " Time management فن إدارة الوقت "
How to succeed " Time management فن إدارة الوقت "How to succeed " Time management فن إدارة الوقت "
How to succeed " Time management فن إدارة الوقت "Ahmed Yehia
 

En vedette (17)

Parasympathethic system
Parasympathethic systemParasympathethic system
Parasympathethic system
 
Hungary
HungaryHungary
Hungary
 
нім. клуб
нім. клубнім. клуб
нім. клуб
 
Package
PackagePackage
Package
 
Magnat_2015
Magnat_2015Magnat_2015
Magnat_2015
 
Comics Naty
Comics NatyComics Naty
Comics Naty
 
Package
PackagePackage
Package
 
Narrativa gráfica-Ofelia Romero
Narrativa gráfica-Ofelia RomeroNarrativa gráfica-Ofelia Romero
Narrativa gráfica-Ofelia Romero
 
Present simple
Present simplePresent simple
Present simple
 
FINAKO
FINAKOFINAKO
FINAKO
 
Plessy vs ferguson
Plessy vs fergusonPlessy vs ferguson
Plessy vs ferguson
 
Grammar book 3
Grammar book 3Grammar book 3
Grammar book 3
 
Presentasi ppdb
Presentasi ppdbPresentasi ppdb
Presentasi ppdb
 
PAE DM2+ HES+IRA
PAE DM2+ HES+IRAPAE DM2+ HES+IRA
PAE DM2+ HES+IRA
 
Responsabilidades enfermeria
Responsabilidades enfermeriaResponsabilidades enfermeria
Responsabilidades enfermeria
 
How to succeed " Time management فن إدارة الوقت "
How to succeed " Time management فن إدارة الوقت "How to succeed " Time management فن إدارة الوقت "
How to succeed " Time management فن إدارة الوقت "
 
PROCESO CIRROSIS HEPATICA
PROCESO CIRROSIS HEPATICAPROCESO CIRROSIS HEPATICA
PROCESO CIRROSIS HEPATICA
 

Similaire à Introduction Clojure - Geneva JUG - Octobre 2012

20080610 04 - Explorations visuelles de programmes
20080610 04 - Explorations visuelles de programmes20080610 04 - Explorations visuelles de programmes
20080610 04 - Explorations visuelles de programmesLeClubQualiteLogicielle
 
Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Claude Falguiere
 
Introduction à scala
Introduction à scalaIntroduction à scala
Introduction à scalaSOAT
 
Mix it 2011 - Clojure
Mix it 2011 - ClojureMix it 2011 - Clojure
Mix it 2011 - Clojurelolopetit
 
Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2) Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2) Frank Denis
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab ElasticsearchDavid Pilato
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5halleck45
 
WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013Zenika
 
Présentation Groovy
Présentation GroovyPrésentation Groovy
Présentation Groovyguest6e3bed
 
Présentation Groovy
Présentation GroovyPrésentation Groovy
Présentation GroovyJS Bournival
 
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Loic Yon
 
Claire epita-février2014
Claire epita-février2014Claire epita-février2014
Claire epita-février2014Yves Caseau
 
Java-3eme partie.pptx
Java-3eme partie.pptxJava-3eme partie.pptx
Java-3eme partie.pptxHassanAbdel
 
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...Alexandre Monnin
 
Mat lab1
Mat lab1Mat lab1
Mat lab1fouadDD
 
ALF 11 - Diagramme de flux de contrôle et WebAssembly
ALF 11 - Diagramme de flux de contrôle et WebAssemblyALF 11 - Diagramme de flux de contrôle et WebAssembly
ALF 11 - Diagramme de flux de contrôle et WebAssemblyAlexandru Radovici
 

Similaire à Introduction Clojure - Geneva JUG - Octobre 2012 (20)

20080610 04 - Explorations visuelles de programmes
20080610 04 - Explorations visuelles de programmes20080610 04 - Explorations visuelles de programmes
20080610 04 - Explorations visuelles de programmes
 
Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012
 
Introduction à scala
Introduction à scalaIntroduction à scala
Introduction à scala
 
Université des langages scala
Université des langages   scalaUniversité des langages   scala
Université des langages scala
 
Mix it 2011 - Clojure
Mix it 2011 - ClojureMix it 2011 - Clojure
Mix it 2011 - Clojure
 
Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2) Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2)
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab Elasticsearch
 
Introduction aux interfaces.
Introduction aux interfaces.Introduction aux interfaces.
Introduction aux interfaces.
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5
 
WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013
 
ALF 11 - WebAssembly
ALF 11 - WebAssemblyALF 11 - WebAssembly
ALF 11 - WebAssembly
 
Présentation Groovy
Présentation GroovyPrésentation Groovy
Présentation Groovy
 
Présentation Groovy
Présentation GroovyPrésentation Groovy
Présentation Groovy
 
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
 
Claire epita-février2014
Claire epita-février2014Claire epita-février2014
Claire epita-février2014
 
Java-3eme partie.pptx
Java-3eme partie.pptxJava-3eme partie.pptx
Java-3eme partie.pptx
 
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...
L'ontologie NiceTag : Modéliser les tags à l'aide des graphes nommés RDF (pré...
 
Cours de Matlab
Cours de MatlabCours de Matlab
Cours de Matlab
 
Mat lab1
Mat lab1Mat lab1
Mat lab1
 
ALF 11 - Diagramme de flux de contrôle et WebAssembly
ALF 11 - Diagramme de flux de contrôle et WebAssemblyALF 11 - Diagramme de flux de contrôle et WebAssembly
ALF 11 - Diagramme de flux de contrôle et WebAssembly
 

Introduction Clojure - Geneva JUG - Octobre 2012

  • 1. Introduction à Clojure Pablo Tamarit 30 octobre 2012 Geneva JUG
  • 2. 1999 - 2005 2007 - 2049 EIG CERN 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 ?
  • 3. Avant-goût (def panier [{:nom "pommes", :type :fruits} {:nom "poires", :type :fruits} {:nom "scoubidous", :type :objets}]) (group-by :type panier)  {:fruits [{:type :fruits, :nom "pommes"} {:type :fruits, :nom "poires"}], :objets [{:type :objets, :nom "scoubidous"}]}
  • 4. • Partie philosophique • Partie théorique • Partie pratique
  • 6. Clojure + λ • Créé en 2007 • Tout est immutable • Simplicité • Pas d'état • Pas d’orienté objet! • Pas d'effets de bord • Typage dynamique • Dialecte de Lisp!
  • 8. John McCarthy 1927 – 2011
  • 9. Lisp • Inventé en 1958 • Lots of Irritating Superfluous Parentheses?
  • 10. Lisp • Inventé en 1958 • Homoiconicité • Lots of • Macros Irritating Superfluous Parentheses paulgraham.com/avg.html
  • 12. Langage • Syntaxe simple, vocabulaire riche. – Syntaxe: données, fonctions – Vocabulaire: fonctions clojure.org/cheatsheet
  • 13. Syntaxe: collections Liste ("un" 2 3 3) Vecteur ["un" 2 3 3] Set #{"un" 2 3} Map {:nom "Pablo", :age 28} (:age {:nom "Pablo", :age 28})  28
  • 14. Syntaxe: fonctions fn args liste vecteur Appel (+ 1 2 3) Définition (defn abs [n] (if (neg? n) condition (- n) then n)) else Définition anonyme (fn [x y] (+ (abs x) (abs y))) Définition anonyme sucrée #(+ (abs %1) (abs %2))
  • 15. Vocabulaire: fonctions (def coll [-42 5 -0.1]) (map abs coll)  (42 5 0.1) (reduce + 0 coll)  -37.1 (filter neg? coll)  (-42 -0.1)
  • 16. Interop Java Clojure new JFrame("Titre") (JFrame. "Titre") Color.RED Color/RED frame.setTitle("Titre2") (.setTitle frame "Titre2") 4 frame.getTitle().toLowerCase() (.. frame getTitle toLowerCase) 2 3 frame.add(panel) (doto frame 1 frame.pack() (.add panel) frame.setVisible(true) (.pack) (.setVisible true))
  • 18. Quoi installer? • Rien! <dependency> <groupId>org.clojure</groupId> <artifactId>clojure</artifactId> <version>1.4.0</version> </dependency> • Qui a-t-il dans le JAR? – La librairie – REPL: java -jar clojure.jar – Compilateur: .clj  .class
  • 19. Outils • Build – leiningen – clojure-maven-plugin • IDE – Counterclockwise (Eclipse) – La Clojure (IntelliJ IDEA) – Emacs!
  • 20. Apprentissage • Présentations: – blip.tv/clojure – infoq.com/clojure • Livres: – clojurebook.com – joyofclojure.com • Exercices: – 4clojure.com
  • 22. Crédits graphiques • Logo Clojure: © Tom Hickey (tomhickey.com) • Vue aérienne du LHC: © 2001 CERN (cdsweb.cern.ch/record/42370) • La Trahison des images: © 1929 René Magritte • Duke models: © Sun Microsystems Inc. (duke.kenai.com/models) • Portrait de John McCarthy: © 2006 null0 (flic.kr/p/q39Sg) • L'Appel des cimes: © 1942 René Magritte • La Clairvoyance: © 1936 René Magritte • Cooled Beans: © 2008 Chris Bay (flic.kr/p/4z6CBA) • Gears: © Dima Yagnyuk (thenounproject.com/noun/gears/#icon- No2174, thenounproject.com/Deadtype) • Tools: © Jacob Hardbower (thenounproject.com/noun/tools/#icon- No4684, thenounproject.com/HeartWired)