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 Slide

  2. View Slide

  3. Raphael Amorim
    This is me :P

    View Slide

  4. WHAT’S CLOJURE
    ?

    View Slide

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

    View Slide

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

    View Slide

  7. TAKING NOTES.

    View Slide

  8. - Started in 2007

    - Created by Rich Hickey

    - Under Eclipse Public License
    TAKING NOTES.

    View Slide

  9. “ 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 Slide

  10. FUNCIONAL PARADIGM?

    View Slide

  11. Back to the Past.

    View Slide

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

    View Slide

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

    View Slide

  14. 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 Slide

  15. “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 Slide

  16. 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 Slide

  17. Definitions

    View Slide

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

    View Slide

  19. So…

    View Slide

  20. Take values and return values.

    View Slide

  21. Same argument, same result.

    View Slide

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

    View Slide

  23. NO SIDE EFFECTS.

    View Slide

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

    View Slide

  25. Syntax?

    View Slide

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

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

    - String ( “barbante” )

    - Boolean ( true, false )

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

    View Slide

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

    - null ( nil )

    View Slide

  28. 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 Slide

  29. 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 Slide

  30. Clojure REPL

    View Slide

  31. There’s NO interpreter

    View Slide

  32. "Laziness is a virtue"

    View Slide

  33. "Laziness is a virtue"

    View Slide

  34. Clojure Concurrency?

    View Slide

  35. Clojure Concurrency

    View Slide

  36. Clojure Concurrency

    View Slide

  37. Today…
    To avoid Deadlocks:

    View Slide

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

    View Slide

  39. “ Locks are the Enemy ”

    View Slide

  40. STM
    Software Transactional Memory

    View Slide

  41. NO BLOCKING

    View Slide

  42. NO LOCKS

    View Slide

  43. PERSISTENT COLLECTIONS

    View Slide

  44. Clojure IS much more…

    View Slide

  45. • 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 Slide

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

    View Slide

  47. Thanks!!
    @raphamundi

    View Slide