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

The ideas of Clojure - Things I learn from Clojure

Randy Lien
December 06, 2015

The ideas of Clojure - Things I learn from Clojure

A basic Clojure introduction.

Randy Lien

December 06, 2015
Tweet

More Decks by Randy Lien

Other Decks in Programming

Transcript

  1. "Hickey is the new Messiah of software development. Watch and

    listen to his talks, and you will understand." – http://bepsays.com/2014/07/08/how-rich-is-rich-hickey/
  2. Philosophy Focus Simplicity Empowerment Pure functions Expressive Practical Clarity
 Consistency

    Separation 
 of 
 concerns Concise Direct Interop - The Joy of Clojure
  3. Philosophy - Focus • Syntax will not bother you •

    Consistency • Dynamic System • Almost everything defined in Clojure can be redefined (Even while program is running) • Use Macro you can build anything you want to do
  4. Philosophy - Empowerment • Use Java Virtual Machine • Java

    is mature and has many libraries • JavaScript is everywhere (ClojureScript)
  5. Data Types • Integers - 123 • Doubles - 1.23

    • Ratios - 1/23 • Strings - "JCConf" • "Double Quotes Only" • Characters - \J \C
  6. Data Types (cont.) • Symbols - bar • Keywords -

    :foo • Booleans - true false • Null - nil • Regex - #"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+"
  7. Data Structure • Lists - (1 2 3) • Prepend

    • Vectors - [1 2 3] • Zero indexed. Append • Maps - {:a 1, :b 2, :c "3"} • Key-value pair • Comma will be ignored • Sets - #{1 2 3} • Unique. Unordered
  8. Clojure • (+ 1 2) • (+ 1 2 3)

    • (into [] 2) General • 1 + 2 • 1 + 2 + 3 • [].push(2)
  9. functions & composition • map, reduce, filter • partial, comp

    • iterate • repeat, repeatedly • Many built-in functions and you don’t need to create.
 Just compose it!
  10. Why immutable? • No resource limitation • Persistent data structure

    • Record - Share the same data • Key to do functional programming • No side effect • atom is mutable
  11. REPL ? • Read–Eval–Print Loop • nREPL (network REPL) •

    Good for doing TDD • clojure.test • ClojureScript - Browser can connect to nREPL
  12. Summary • Clojure is a practical functional programming language •

    Java and JavaScript are two major languages and Clojure and ClojureScript can run on them • Using REPL in your TDD practices would be helpful • Pure functions and Immutable data structure can make your system stable and easy to reason about
  13. Summary (cont.) • Clojure has much better tooling and keep

    improving it • ClojureScript is hotter than Clojure! • Many companies are using Clojure • booking.com, Yahoo, Puppet, Walmart, twitter, heroku, nubank…etc • STM, transducer, core.asyn
  14. If you want to know more… • Living Clojure •

    The Joy of Clojure • ClojureScript Unraveled • Clojure Applied • Clojure for the Brave and True
  15. Worth to watch • Simple Made Easy • Clojure Made

    Simple • The Value of Values • The Language of the System