4. Functional programming: What,
why?
● Simplicity: Limit state, side-effects
○ Referential transparency
○ Immutable persistent data structures
○ STM, agents etc.
○ => concurrency
● Higher abstractions, including
○ HOF: More reuse - compose behavior
○ Multimethods: Dispatch on any argument(s)
● Language maintains state (lex. scope, loop)
● Generic operations on generic data structs
● Key design question: What it does?
5. You may ask
Why hasn't FP taken the world over yet?
6. But then we could also ask
Why became OOP, available since Simula 67,
only popular in 90s?
(Even though Smalltalk is more OO than Java and C++ and available since
'81.)
It takes time, money, opportunity, optimization, and luck for concepts to take
hold.
7. Why Clojure?
● It's different
○ Functional - new paradigm, back-port learnings
● It's Lisp - the most powerful language ever
○ Macros - infinite abstraction
○ Write the language fitting the domain first
● It runs on JVM
○ Reuse, interoperab., mature and available platform
● Designed for concurrency
8. Lisp is worth learning for the profound
enlightenment experience you will have when
you finally get it; that experience will make you
a better programmer for the rest of your days,
even if you never actually use Lisp itself a lot.
Eric S. Raymond, "How to Become a Hacker"
9. Clojure: Basic Facts
● Functional language for JVM (and .net, JS)
● Dynamically-typed
● Good Java interoperability
● 2006 started, 2009 v1.0, 2011 v1.3
● A Lisp ('58) dialect
● Emphasis on simplicity
● Designed for concurrency
○ STM, agents, immutability, ...
● Flexible, extensible
● Support for objects
● Code <=> data
10. Clojure Syntax
(function arg1 arg2 ...)
(list 1 2 3 4 5)
(+ 1 2 3)
(def square (fn [x] (* x x)))
Lists - and that's all!
● Well, nearly - also 13 'special forms' (def, if,
let, fn, try, ..)
● Few data types: '(), [], #{}, {}
● Literals: 1, "str", :key, symbol