SlideShare une entreprise Scribd logo
1  sur  63
( s im p le
   ( c lo ju r e ) )

C lo ju r e m a d e
     s im p le
                       Ta l k
W h a t is
C lo ju r e
Clojure is small and flexible
Clojure concepts
Encourages Pure Functional approach
- use STM to change state


Functions as first class citizens
  - functions as arguments as they return a value


Make JVM interoperation simple
  - easy to use your existing Java applications
A better Lisp !
Sensible () usage


Sensible macro names


JVM Interoperability
Which LISP is your wingman ?
Common Lisp        Clojure
The dark side of Clojure



         ( x )
The dark side of Clojure



      ( ( x ) )
The dark side of Clojure



    ( ( ( x ) ) )
The dark side of Clojure



 ( ( ( ( x ) ) ) )
The dark side of Clojure



( ( ( ( ( x ) ) ) ) )
...verses non-lisp languages




      ( ) ==
     { ( ) };
Well nearly....


 ([] ((())))
        ==
{ ( {( []) }) };
C o m p a r in g
    J a va
    w it h
  C lo ju r e
It s a ll b y t e c o d e in t h e
               e nd ..
Any object in clojure is just a regular java object




A reference type inheriting from:
         j ava. l ang. obj ec t
B a s ic
C lo ju r e
S yn ta x
Name-spaces
; Define a namespace
  ( ns nam s pac e- nam
          e-           e)

; Include namespace code
  ( us e ' nam - s pac e- nam
              es             e)

Groups code together like a package statement
 in Java
Defining a function
 First principles            Syntactic Sugar
 ( def nam   e               ( def n nam e
    ( f n [ ar gs ]            [ ar gs ]
      ( f unc t i on- body      ( f unc t i on-
   …) )
    )                          body . . . ) )

( def n w c om m s age [ nam ]
           el      e- es             e
   ( pr i nt l n ( s t r “ W c om t o Cl oj ur e ”
                            el   e
nam )e)
Special forms
Special evaluation rules for the Clojure compiler
  - part of the language definition


catch, def, do, dot ('.'), finally, fn, if, let, loop,
  monitor-enter, monitor-exit, new, quote,
  recur, set!, throw, try and var
Simple function example
Define a simple function

( def n hel l o- w l d [ nam
                      or          e]
   ( pr i nt l n( s t r " Hel l o "
  nam ) )
      e)

Call the function in the REPL or in your code
( hel l o- w l d " j r 0c ket " )
            or
Prefix notation



( def n s quar e- t he- number
  [ x]
    ( * x x) )
“Overloading” functions

( def n make
   ([ ]    ; do       t h e f o l l o wi n g f u n c t i o n i f
 n o ar g s

        ( s t r uc t vec t or 0 0) )
     ( [ x y]        ; d o i f x an d y ar e
 ar g u me n t s

         ( s t r uc t vec t or x y) )
 )
Im m u t a b le
    D a ta
s truc ture s
List – Ordered collection

( l i s t 1 3 5 7)

' ( 1 3 5 7)

 ( 1 2 3) ; 1 i s n o t a
  f unct i on
Vectors – hashed ordered list
[ : m r i x- c har ac t er s [ : neo
     at
   : m pheus : t r i ni t y : s m t h] ]
      or                          i


( f i r s t [ : n e o : mo r p h e u s : t r i n i t y
   : s mi t h ] )


( nt h [ : mat r i x : b ab yl o n 5 : f i r e f l y
  : s t ar g at e ] 2 )


( c onc at [ : n e o ] [ : t r i n i t y] )
Maps – unordered key/values
{ : a 1 : b 2}                                { : a { : a 1} }
    { : a 1 , : b 2}                             {: a {: a 1}}


{ :a 1 :b }                                   { { : a 1} : a}
j ava. l an g . Ar r ayI n d e x Ou t Of Bo      { { : a 1 } : a}
   u n d s Ex c e p t i o n : 3
                                              ; i d i om - put : a on t he
                                                left
{ : a 1 : b 2}
    { : a 1 , : b 2}
L is t s a r e f o r
       c ode

Ve c t o r s a r e
  fo r d a ta
Working with data
(last [1 1 2 3 5 8])        (doc last)


(defn penultimate [x]
 (last (butlast x)) )       (doc butlast)


(penultimate [1 2 3 4 5])
And more...
(nth [1 1 2 3 5 8] 2)


(count [1 1 2 3 5 8])


(reverse [1 1 2 3 5 8])


(defn palindrome? [x]     Proposition – naming
 (= x (reverse x)) )       convention
Even more
(flatten [[1 1] 2 [3 [5 8]]])


(compress "aaaabccaadeeee")


(encode "aaaabccaadeeee")


(replicate 10 "a")
Defining a data structure
( def m dat a- s t r uc t ur e
        y-
 [ dat a ] )

( def days - of - t he- week
  [ “Monday” “ Tues day”
 “W ednes day” ] )
Example data structure


( def j r 0c ket
   { : f i r s t - nam " J ohn" ,
                      e

    : l as t - name
 " St evens on" } )
G e t c o d in g !
c lo ju r e .
           org
d o c s . c lo ju r
     e .o rg
All hail the REPL
An interactive shell for
 clojure

Fast feedback loop
 for clojure
M a n a g in g a
   c lo ju r e
   p r o je c t
Maven
Just like any other Java project


Step 1)
Add Clojure library jar to your POM


Step 2)
Download the Internet !!!
le in in g e n
   Leiningen
                               .o rg




lein new     Create a new clojure project
lein deps    Download all dependencies
lein repl    Start the interactive shell (repl)
lein swank   Start repl server
Ema c s
A fe w
in t e r e s t in g
   C lo ju r e
 e x a m p le s
str
(str h e l l o)         Concatenate strings
                              together
                               represent a
                                 character using 


(def data “boo”)             Join arguments with
(str “message” data )          strings
Ratio
Unique data type            ( / 3 5)
                            ( / 3. 0
Allow lazy evaluation
                              5)
Avoid loss of precision
                            (/ 1 3)
                            (/ 1.0 3)

                            (class (/ 1
Calling Java... ooooo!!
( j avax . s wi n g . JOp t i o n Pan e /
    s h o wMe s s ag e D i al o g n i l
        " He l l o W r l d " )
                     o
Importing Java into Clojure
( ns dr aw ng- dem
          i       o
   ( : i m t [ j avax. s w ng J panel
          por             i
 J Fr am  e]
            [ j ava. awt
 Di m i on] ) )
     ens
Working with Java
Java Classes
  fullstop after class name
  ( J Fr am )
           e.
  (Math/cos 3) ; static method call

Java methods
  fullstop before method name
  ( . get Cont ent Pane f r am ;;method name first
                              e)
  ( . f r am get Cont ent Pane) ;;object first
            e
What class is that...
(class (str "Jr0cket"))
java.lang.String


(class (defn hello-world [name] (str "Hello
  cruel world")))
clojure.lang.Var
Clojure calling Java web stuff
( l et [ c onn]
    ( dot o ( Ht t pUr l Connec t i on.
  Ur l )
       ( . s et Reques t M hod
                          et
     “ POST” )
       ( . s et DoOut put t r ue)

   ( . s et I ns t aneFol l ow   Redi r ec t
   s                 t r ue) ) ] )
Recursive functions
Functions that call   Tail recursion
 themselves           Avoids blowing the
                       stack
Fractal coding
                      A trick as the JVM does
                       not support tail
                       recursion directly :-(
Tail recursion
( def n r ec ur s i ve- c ount er
   ( pr i nt ans w )er
   ( i f ( < ans w  er 1000)
     (   r ec ur   ( + ans wer 4) ) ) )
Where to find out more...


c l oj ur e. or g/ c heat s h
             eet
M u t a b le S t a t e
Software Transactional Memory

Provides safe, concurrent access to memory


Agents allow encapsulated access to mutable
 resources
Functional for the web
Big blog of stuff in > Big blob of stuff out


Encourages modularising responsibilities


Good at processing data in parallel
Noir   w e b n o ir . o r g
M o re to
             c o m e ...
          c l oj ur e. or g
       dev. c l oj ur e. or g

              @ r 0c ket
               j
c l oj ur e. j r 0c ket . c o

Contenu connexe

Tendances

Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2Yeqi He
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languagePawel Szulc
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance PythonIan Ozsvald
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Tcl2012 8.6 Changes
Tcl2012 8.6 ChangesTcl2012 8.6 Changes
Tcl2012 8.6 Changeshobbs
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And BeyondMike Fogus
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode CompilerDonal Fellows
 
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5PyNSK
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent SevenMike Fogus
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. ExperienceMike Fogus
 

Tendances (20)

Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Tcl2012 8.6 Changes
Tcl2012 8.6 ChangesTcl2012 8.6 Changes
Tcl2012 8.6 Changes
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Adventures in TclOO
Adventures in TclOOAdventures in TclOO
Adventures in TclOO
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
 

Similaire à Clojure made simple - Lightning talk

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
Predictably
PredictablyPredictably
Predictablyztellman
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrencyAlex Navis
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議dico_leque
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»DataArt
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slidejonycse
 
Prolog 01
Prolog 01Prolog 01
Prolog 01saru40
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingGarth Gilmour
 
Clojure Interoperability
Clojure InteroperabilityClojure Interoperability
Clojure Interoperabilityrik0
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Similaire à Clojure made simple - Lightning talk (20)

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Predictably
PredictablyPredictably
Predictably
 
Music as data
Music as dataMusic as data
Music as data
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrency
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Scala
ScalaScala
Scala
 
Prolog 01
Prolog 01Prolog 01
Prolog 01
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Clojure Interoperability
Clojure InteroperabilityClojure Interoperability
Clojure Interoperability
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 

Plus de John Stevenson

ClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of ClojureClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of ClojureJohn Stevenson
 
Confessions of a developer community builder
Confessions of a developer community builderConfessions of a developer community builder
Confessions of a developer community builderJohn Stevenson
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptJohn Stevenson
 
Introduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptIntroduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptJohn Stevenson
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Communication improbable
Communication improbableCommunication improbable
Communication improbableJohn Stevenson
 
Getting into public speaking at conferences
Getting into public speaking at conferencesGetting into public speaking at conferences
Getting into public speaking at conferencesJohn Stevenson
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojureJohn Stevenson
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with ClojureJohn Stevenson
 
Guiding people into Clojure
Guiding people into ClojureGuiding people into Clojure
Guiding people into ClojureJohn Stevenson
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperJohn Stevenson
 
Get Functional Programming with Clojure
Get Functional Programming with ClojureGet Functional Programming with Clojure
Get Functional Programming with ClojureJohn Stevenson
 
So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?John Stevenson
 
Trailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App CloudTrailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App CloudJohn Stevenson
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
 
Introducing the Salesforce platform
Introducing the Salesforce platformIntroducing the Salesforce platform
Introducing the Salesforce platformJohn Stevenson
 
Dreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version ControlDreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version ControlJohn Stevenson
 
Salesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - IntroductionSalesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - IntroductionJohn Stevenson
 
Heroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & servicesHeroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & servicesJohn Stevenson
 
Developers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 PlatformDevelopers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 PlatformJohn Stevenson
 

Plus de John Stevenson (20)

ClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of ClojureClojureX Conference 2017 - 10 amazing years of Clojure
ClojureX Conference 2017 - 10 amazing years of Clojure
 
Confessions of a developer community builder
Confessions of a developer community builderConfessions of a developer community builder
Confessions of a developer community builder
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
 
Introduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptIntroduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with Clojurescript
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Communication improbable
Communication improbableCommunication improbable
Communication improbable
 
Getting into public speaking at conferences
Getting into public speaking at conferencesGetting into public speaking at conferences
Getting into public speaking at conferences
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 
Guiding people into Clojure
Guiding people into ClojureGuiding people into Clojure
Guiding people into Clojure
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Get Functional Programming with Clojure
Get Functional Programming with ClojureGet Functional Programming with Clojure
Get Functional Programming with Clojure
 
So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?So you want to run a developer event, are you crazy?
So you want to run a developer event, are you crazy?
 
Trailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App CloudTrailhead live - Overview of Salesforce App Cloud
Trailhead live - Overview of Salesforce App Cloud
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Introducing the Salesforce platform
Introducing the Salesforce platformIntroducing the Salesforce platform
Introducing the Salesforce platform
 
Dreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version ControlDreamforce14 Metadata Management with Git Version Control
Dreamforce14 Metadata Management with Git Version Control
 
Salesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - IntroductionSalesforce Summer of Hacks London - Introduction
Salesforce Summer of Hacks London - Introduction
 
Heroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & servicesHeroku Introduction: Scaling customer facing apps & services
Heroku Introduction: Scaling customer facing apps & services
 
Developers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 PlatformDevelopers guide to the Salesforce1 Platform
Developers guide to the Salesforce1 Platform
 

Dernier

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Dernier (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Clojure made simple - Lightning talk

  • 1. ( s im p le ( c lo ju r e ) ) C lo ju r e m a d e s im p le Ta l k
  • 2. W h a t is C lo ju r e
  • 3.
  • 4.
  • 5. Clojure is small and flexible
  • 6. Clojure concepts Encourages Pure Functional approach - use STM to change state Functions as first class citizens - functions as arguments as they return a value Make JVM interoperation simple - easy to use your existing Java applications
  • 7. A better Lisp ! Sensible () usage Sensible macro names JVM Interoperability
  • 8. Which LISP is your wingman ? Common Lisp Clojure
  • 9. The dark side of Clojure ( x )
  • 10. The dark side of Clojure ( ( x ) )
  • 11. The dark side of Clojure ( ( ( x ) ) )
  • 12. The dark side of Clojure ( ( ( ( x ) ) ) )
  • 13. The dark side of Clojure ( ( ( ( ( x ) ) ) ) )
  • 14. ...verses non-lisp languages ( ) == { ( ) };
  • 15. Well nearly.... ([] ((()))) == { ( {( []) }) };
  • 16. C o m p a r in g J a va w it h C lo ju r e
  • 17. It s a ll b y t e c o d e in t h e e nd .. Any object in clojure is just a regular java object A reference type inheriting from: j ava. l ang. obj ec t
  • 18.
  • 19. B a s ic C lo ju r e S yn ta x
  • 20. Name-spaces ; Define a namespace ( ns nam s pac e- nam e- e) ; Include namespace code ( us e ' nam - s pac e- nam es e) Groups code together like a package statement in Java
  • 21. Defining a function First principles Syntactic Sugar ( def nam e ( def n nam e ( f n [ ar gs ] [ ar gs ] ( f unc t i on- body ( f unc t i on- …) ) ) body . . . ) ) ( def n w c om m s age [ nam ] el e- es e ( pr i nt l n ( s t r “ W c om t o Cl oj ur e ” el e nam )e)
  • 22. Special forms Special evaluation rules for the Clojure compiler - part of the language definition catch, def, do, dot ('.'), finally, fn, if, let, loop, monitor-enter, monitor-exit, new, quote, recur, set!, throw, try and var
  • 23. Simple function example Define a simple function ( def n hel l o- w l d [ nam or e] ( pr i nt l n( s t r " Hel l o " nam ) ) e) Call the function in the REPL or in your code ( hel l o- w l d " j r 0c ket " ) or
  • 24. Prefix notation ( def n s quar e- t he- number [ x] ( * x x) )
  • 25. “Overloading” functions ( def n make ([ ] ; do t h e f o l l o wi n g f u n c t i o n i f n o ar g s ( s t r uc t vec t or 0 0) ) ( [ x y] ; d o i f x an d y ar e ar g u me n t s ( s t r uc t vec t or x y) ) )
  • 26. Im m u t a b le D a ta s truc ture s
  • 27. List – Ordered collection ( l i s t 1 3 5 7) ' ( 1 3 5 7) ( 1 2 3) ; 1 i s n o t a f unct i on
  • 28. Vectors – hashed ordered list [ : m r i x- c har ac t er s [ : neo at : m pheus : t r i ni t y : s m t h] ] or i ( f i r s t [ : n e o : mo r p h e u s : t r i n i t y : s mi t h ] ) ( nt h [ : mat r i x : b ab yl o n 5 : f i r e f l y : s t ar g at e ] 2 ) ( c onc at [ : n e o ] [ : t r i n i t y] )
  • 29. Maps – unordered key/values { : a 1 : b 2} { : a { : a 1} } { : a 1 , : b 2} {: a {: a 1}} { :a 1 :b } { { : a 1} : a} j ava. l an g . Ar r ayI n d e x Ou t Of Bo { { : a 1 } : a} u n d s Ex c e p t i o n : 3 ; i d i om - put : a on t he left { : a 1 : b 2} { : a 1 , : b 2}
  • 30. L is t s a r e f o r c ode Ve c t o r s a r e fo r d a ta
  • 31. Working with data (last [1 1 2 3 5 8]) (doc last) (defn penultimate [x] (last (butlast x)) ) (doc butlast) (penultimate [1 2 3 4 5])
  • 32. And more... (nth [1 1 2 3 5 8] 2) (count [1 1 2 3 5 8]) (reverse [1 1 2 3 5 8]) (defn palindrome? [x] Proposition – naming (= x (reverse x)) ) convention
  • 33. Even more (flatten [[1 1] 2 [3 [5 8]]]) (compress "aaaabccaadeeee") (encode "aaaabccaadeeee") (replicate 10 "a")
  • 34. Defining a data structure ( def m dat a- s t r uc t ur e y- [ dat a ] ) ( def days - of - t he- week [ “Monday” “ Tues day” “W ednes day” ] )
  • 35. Example data structure ( def j r 0c ket { : f i r s t - nam " J ohn" , e : l as t - name " St evens on" } )
  • 36. G e t c o d in g !
  • 37. c lo ju r e . org d o c s . c lo ju r e .o rg
  • 38. All hail the REPL An interactive shell for clojure Fast feedback loop for clojure
  • 39.
  • 40.
  • 41. M a n a g in g a c lo ju r e p r o je c t
  • 42. Maven Just like any other Java project Step 1) Add Clojure library jar to your POM Step 2) Download the Internet !!!
  • 43. le in in g e n Leiningen .o rg lein new Create a new clojure project lein deps Download all dependencies lein repl Start the interactive shell (repl) lein swank Start repl server
  • 44.
  • 46.
  • 47.
  • 48. A fe w in t e r e s t in g C lo ju r e e x a m p le s
  • 49. str (str h e l l o) Concatenate strings together represent a character using (def data “boo”) Join arguments with (str “message” data ) strings
  • 50. Ratio Unique data type ( / 3 5) ( / 3. 0 Allow lazy evaluation 5) Avoid loss of precision (/ 1 3) (/ 1.0 3) (class (/ 1
  • 51. Calling Java... ooooo!! ( j avax . s wi n g . JOp t i o n Pan e / s h o wMe s s ag e D i al o g n i l " He l l o W r l d " ) o
  • 52. Importing Java into Clojure ( ns dr aw ng- dem i o ( : i m t [ j avax. s w ng J panel por i J Fr am e] [ j ava. awt Di m i on] ) ) ens
  • 53. Working with Java Java Classes fullstop after class name ( J Fr am ) e. (Math/cos 3) ; static method call Java methods fullstop before method name ( . get Cont ent Pane f r am ;;method name first e) ( . f r am get Cont ent Pane) ;;object first e
  • 54. What class is that... (class (str "Jr0cket")) java.lang.String (class (defn hello-world [name] (str "Hello cruel world"))) clojure.lang.Var
  • 55. Clojure calling Java web stuff ( l et [ c onn] ( dot o ( Ht t pUr l Connec t i on. Ur l ) ( . s et Reques t M hod et “ POST” ) ( . s et DoOut put t r ue) ( . s et I ns t aneFol l ow Redi r ec t s t r ue) ) ] )
  • 56. Recursive functions Functions that call Tail recursion themselves Avoids blowing the stack Fractal coding A trick as the JVM does not support tail recursion directly :-(
  • 57. Tail recursion ( def n r ec ur s i ve- c ount er ( pr i nt ans w )er ( i f ( < ans w er 1000) ( r ec ur ( + ans wer 4) ) ) )
  • 58. Where to find out more... c l oj ur e. or g/ c heat s h eet
  • 59. M u t a b le S t a t e
  • 60. Software Transactional Memory Provides safe, concurrent access to memory Agents allow encapsulated access to mutable resources
  • 61. Functional for the web Big blog of stuff in > Big blob of stuff out Encourages modularising responsibilities Good at processing data in parallel
  • 62. Noir w e b n o ir . o r g
  • 63. M o re to c o m e ... c l oj ur e. or g dev. c l oj ur e. or g @ r 0c ket j c l oj ur e. j r 0c ket . c o

Notes de l'éditeur

  1. Hickey&apos;s primary interest was concurrency — he wanted the ability to write multi-threaded applications, but increasingly found the mutable, stateful paradigm of object oriented programming to be part of the problem The idea of a functional Lisp integrated with a commercially accepted host platform just seemed like chocolate and peanut butter. Coming up with persistent data structures that were fast enough was the tipping point for my considering it viable. functions as first-class objects, meaning that functions can be placed into data structures, passed as arguments to other functions, evaluated in comparisons, even returned as the return value of another function. Moreover, functions do not have &amp;quot;side effects&amp;quot; — the ability to modify program state or data. This paradigm focuses on computation in the mathematical sense, rather than procedural algorithms, and is a completely different approach to programming. Clojure does provide persistent data structures For application developers, the most significant distinction is that Clojure defaults to making all data structures immutable developers must use one of four special mutable structures that are explicitly designed to be shared between threads: refs, vars, atoms, and agents. Clojure uses software transactional memory (STM) to coordinate changing these mutable structures while keeping them in a consistent state, much like a transactional database. This model makes it considerably simpler to write thread-safe code than it is in object oriented languages. No locks are required, therefore there are no deadlocks or race conditions.
  2. Clojure has a programmatic macro system which allows the compiler to be extended by user code You can add your own language features with macros. Clojure itself is built out of macros such as defstruct: (defstruct person :first-name :last-name) If you need different semantics, write your own macro. If you want a variant of structs with strong typing and configurable null-checking for all fields, you can create your own defrecord macro, to be used like this: (defrecord person [String :first-name String :last-name] :allow-nulls false) This ability to reprogram the language from within the language is the unique advantage of Lisp. You will see facets of this idea described in various ways: Lisp is homoiconic - Lisp code is just Lisp data. This makes it easy for programs to write other programs. The whole language is there, all the time. Paul Graham’s essay “Revenge of the Nerds” explains why this is so powerful. http://www.paulgraham.com/icad.html Lisp syntax also eliminates rules for operator precedence and associativity, with fully parenthesized expressions, there is no possible ambiguity
  3. The downside of Lisp’s simple, regular syntax, at least for beginners, is Lisp’s fixation on parentheses and on lists as the core data type. Clojure offers an interesting combination of features that makes Lisp more approachable for non-Lispers.
  4. The downside of Lisp’s simple, regular syntax, at least for beginners, is Lisp’s fixation on parentheses and on lists as the core data type. Clojure offers an interesting combination of features that makes Lisp more approachable for non-Lispers.
  5. The downside of Lisp’s simple, regular syntax, at least for beginners, is Lisp’s fixation on parentheses and on lists as the core data type. Clojure offers an interesting combination of features that makes Lisp more approachable for non-Lispers.
  6. The downside of Lisp’s simple, regular syntax, at least for beginners, is Lisp’s fixation on parentheses and on lists as the core data type. Clojure offers an interesting combination of features that makes Lisp more approachable for non-Lispers.
  7. The downside of Lisp’s simple, regular syntax, at least for beginners, is Lisp’s fixation on parentheses and on lists as the core data type. Clojure offers an interesting combination of features that makes Lisp more approachable for non-Lispers.
  8. When you require a library named clojure.contrib.str-utils, Clojure looks for a file named clojure/contrib/str-utils.clj on the CLASSPATH To avoid having to use the namespace for your library, you have to use refer, like so - (refer &apos;examples/introduction) The use function does both require refer, like so – (use &apos;examples.introduction) o force a library to reload: (use :reload-all &apos;examples.introduction) The :reload-all flag is useful if you are making changes and want to see results without restarting the REPL.
  9. (defn …) is syntactic sugar for (def name (function [] … ) Most people use the defn shortcut as its much more readable.
  10. This is barfing because the evaluator has to keep around state for each call due to the expression (* x (factorial (- x 1))) . We need to make this function tail recursive. recur can be thought of as the Clojure operator for looping. Think of it like a function call for the nearest enclosing let or function definition supplied with new variables. Naively we can switch over to using this by doing: user&gt; (defn factorial2 [x] (if (= x 0) 1 (* x (recur (- x 1))))) But this is a compile-time error (which in itself is pretty neat!). java.lang.UnsupportedOperationException: Can only recur from tail position (NO_SOURCE_FILE:4) An accumulator parameter is an extra parameter to a function that&apos;s used to gather intermediate parts of the calculation. If we do this, we can make sure that the recur call is in the tail position. Using an anonymous function we get: (defn factorial3 [x] ((fn [x y] (if (= x 0) y (recur (- x 1) (* x y)))) x 1)) Now when recur is used, it doesn&apos;t need to keep any of the previous stack frame around. This means we can finally calculate factorial 1000000, which begins with 282 and ends with lots of zeros!
  11. Hiccup library for representing HTML in Clojure. It uses vectors to represent tags, and maps to represent a tag&apos;s attributes.