Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Clojure

Intro to Clojure

Slides of my Lecture in the Academic Computer Science week - UFF 2015

Raphael Amorim

November 26, 2015
Tweet

More Decks by Raphael Amorim

Other Decks in Programming

Transcript

  1. CLOJURE
    Intro to
    @raphamundi

    View full-size slide

  2. Raphael Amorim
    This is me :P

    View full-size slide

  3. WHAT’S CLOJURE
    ?

    View full-size slide

  4. WHAT’S CLOJURE?
    Clojure is a dynamic programming
    language that targets the Java Virtual
    Machine (and the CLR, and JavaScript).

    View full-size slide

  5. WHO’S USING CLOJURE?
    Akamai, Appvise, Citigroup, Amazon,
    eBay, Heroku, Groupon, Netflix, Nubank,
    Salesforce, Walmart Labs, Zendesk […]
    http://clojure.org/Companies

    View full-size slide

  6. TAKING NOTES.

    View full-size slide

  7. - Started in 2007

    - Created by Rich Hickey

    - Under Eclipse Public License
    TAKING NOTES.

    View full-size slide

  8. “ Clojure is a dialect of Lisp, and shares with
    Lisp the code-as-data philosophy and a
    powerful macro system. Clojure is predominantly
    a functional programming language ”
    TAKING NOTES.

    View full-size slide

  9. FUNCIONAL PARADIGM?

    View full-size slide

  10. Back to the Past.

    View full-size slide

  11. λ - 1930
    The Lambda Calculus Appears
    Back to the Past.

    View full-size slide

  12. Lisp - 1958
    Introduced a programming language able
    to deal with mathematical notation
    Back to the Past.

    View full-size slide

  13. Lisp - 1958
    Introduced a programming language able
    to deal with mathematical notation
    * IPL (Information Processing Language) is sometimes cited as the first
    computer-based functional programming language. First appeared in 1956.
    Back to the Past.

    View full-size slide

  14. “Can Programming Be Liberated
    from the von Neumann Style?” - 1978
    John Backus (FORTRAN creator) criticizes hardware architecture
    based on von Neuman model.
    Back to the Past.

    View full-size slide

  15. The Boom- 1980
    Innovative techniques have been proposed, such as: Lazy Evaluation
    Emergence of other languages such as: Lazy ML, Orwell, Alfl, Id,
    Clean, Ponder e Daisy
    Back to the Past.

    View full-size slide

  16. Definitions

    View full-size slide

  17. Treats computation as the evaluation of mathematical
    functions and avoids changing-state and mutable data.

    View full-size slide

  18. Take values and return values.

    View full-size slide

  19. Same argument, same result.

    View full-size slide

  20. Testing is easier, because there’s
    no state.

    View full-size slide

  21. NO SIDE EFFECTS.

    View full-size slide

  22. NO SIDE EFFECTS.
    Almost (e.g: I/O)

    View full-size slide

  23. - Numbers ( 1, 3, 5, 85 )

    - Character ( \h, \r, \a )

    - String ( “barbante” )

    - Boolean ( true, false )

    - Symbol ( ‘a, ‘b, ‘c )

    View full-size slide

  24. - Keywords ( :bad, :cool, :ugly )

    - null ( nil )

    View full-size slide

  25. Collections (all of them are immutable)

    - Lists ( '(1 2 3 4) )

    - sequential and counted, not associative

    - first and rest

    - Vector ( [ 1 2 101 85 ] )

    - sequential, counted and associative

    - access by key

    View full-size slide

  26. Collections (all of them are immutable)

    - Maps ( { “raphael” 20, “richard" 25, “chuck” 99 } )

    - counted and associative, not sequential

    - access by key

    - Sets ( #{“hugo” “raphael” “vianna”} )

    - counted, not sequential, not associative

    - lookup for containment

    View full-size slide

  27. Clojure REPL

    View full-size slide

  28. There’s NO interpreter

    View full-size slide

  29. "Laziness is a virtue"

    View full-size slide

  30. "Laziness is a virtue"

    View full-size slide

  31. Clojure Concurrency?

    View full-size slide

  32. Clojure Concurrency

    View full-size slide

  33. Clojure Concurrency

    View full-size slide

  34. Today…
    To avoid Deadlocks:

    View full-size slide

  35. Timeout and Retry?
    Specific Lock Order?
    Coarse Locks?

    View full-size slide

  36. “ Locks are the Enemy ”

    View full-size slide

  37. STM
    Software Transactional Memory

    View full-size slide

  38. PERSISTENT COLLECTIONS

    View full-size slide

  39. Clojure IS much more…

    View full-size slide

  40. • Clojure:Functional Concurrency for the JVM - Howard M. Lewis Ship
    • Clojure: A dynamic programming language for the JVM - Rich Hickey
    • Intro to Clojure by Balint Erdi ( https://speakerdeck.com/balint/intro-
    to-clojure )
    • Clojure Intro ( http://www.slideshare.net/thnetos/clojure-intro )
    • Introduction to Clojure by Renzo Borgatti ( http://pt.slideshare.net/
    reborg/introduction-to-clojure-13679039 )
    References

    View full-size slide

  41. • http://www.braveclojure.com/getting-started/
    References

    View full-size slide

  42. Thanks!!
    @raphamundi

    View full-size slide