The design of Clojure

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

The design of Clojure

An outline of how the Clojure programming language is designed to be used.

Shantanu Kumar

February 28, 2016

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

28 slides
  1. Who am I? • Engineer @ Concur • Author of

    “Clojure High Performance Programming” • Open Source enthusiast: https://github.com/ kumarshantanu • @kumarshantanu on Twitter 2
  2. Clojure • Created by Rich Hickey, 2007 • Eclipse Public

    License (OSS) • Website — https://clojure.org/ • Lisp • Functional • Hosted on JVM (and CLR, JS) 3
  3. Big ideas • Pervasive immutability (Epochal time model) • First-class

    values • First-class functions • Performance • Host interoperability • First-class state management 4
  4. Data types • Number: 42, -5.67, 22/7 • Boolean: true,

    false • Character: \x, \y, \newline, \space • String: “foo”, “bar” (multi-line literals are supported) • Symbol: ‘do-something, ‘bizfn • Keyword: :red, :blue • Nothing: nil 8
  5. Data structures • List: ‘(“Harry” 34 :male) — sequential access

    • Map: {:name “Harry” :age 34} • Set: #{:red :blue} • Vector: [“Harry” 34 :male] 9
  6. Persistent Data-structures • Immutable (updates return new instances) • Structure

    sharing (Hash array mapped trie) • 32-way branching for O(<7) performance • Sustained performance across updates • Reference: “Ideal Hash Trees” (Phil Bagwell) 13
  7. –Alan J Perlis “A language that doesn't affect the way

    you think about programming, is not worth knowing.” 16
  8. Records • Class semantics (memory layout) • Behave as maps

    • Immutable in the same way as maps 18
  9. Protocols • Behaviour contract • Polymorphism • Dispatch on target

    object type • Used as implementation details 20
  10. No structural inheritance! But, there are value hierarchies Image source:

    https://xspblog.files.wordpress.com/2008/06/owl_yarly.jpg 21
  11. Concurrent execution • CPU-bound and I/O-bound thread pools • `future`:

    Asynchronous one-time access • `pmap`: Concurrent CPU-bound processing • `promise/deliver`: Single producer-consumer • Java’s concurrent collections considered idiomatic 26
  12. Concurrency and state • Atoms — uncoordinated compare and swap

    • Agents — asynchronous sequential operations • Refs — Software Transactional Memory • Dynamic vars — Thread-local access 27

More Decks by Shantanu Kumar

Other Decks in Programming