"Lisp is over half a century old and it still has this perfect timeless air about it". Clojure is a Lisp. It's a dynamic programming language that targets the JVM and JavaScript.
It's also awesome.
In this talk I'll give you a really quick dive into Clojure programming, show you some of the most important language features and tools, and hopefully inspire you to dig a little deeper yourself.
- My background
- It's gonna be quick in places - stop me at any time and ask for clarifications.
- Links (also at end):
- These slides: git.io/vwlpz
- It's (primarily) functional
- It's a Lisp
- It's not John McCarthy's Lisp
- Dynamic
- Things you can do in Clojure / things inspired by Clojure
- Distributed systems and web services
- Apache Storm
- Om - react.js but faster
- Immutable.js
- Overtone
- Think about verbs not nouns
- See Steve Yegge's Execution in the Kingdom of Nouns
- Data "shape" is important
- Functions are first class
- The de-facto build tool - http://leiningen.org/
- but not the only build tool - Boot
- It's for creating and managing projects
- Read Evaluate Print Loop
- A wealth of choices:
- Emacs + clojure-mode + Cider
- Vim + Fireplace + Cider
- IntelliJ + Cursive
- Nightcode
- (?) Light Table
- Must-have features:
- nREPL integration
- Syntax highlighting
- Auto paren matching
- Structural navigation and editing
(Source: http://www.thejach.com/view/2011/8/short_guide_to_lisp_syntax)
(Source: http://emacslife.com/how-to-read-emacs-lisp.html)
- Numbers, strings, keywords
def
and immutability
- Lists, vectors, maps, sets
- seq ops
first
,rest
conj
for
,doseq
- recursion
- map ops
assoc
,dissoc
map
,filter
reduce
- Data don't change
- Structural sharing used for efficiency
(source: http://debasishg.blogspot.com/2010/05/grokking-functional-data-structures.html)
fn
defn
- Higher order functions
- e.g.
map
takes a function as its second argument
- e.g.
- Threading macros:
->
and->>
let
- local "variables"if
,when
,cond
- Destructuring
- Lazy seqs
- Recursion with (explicit) tail call optimization
- Example: max of a list of numbers
- Namespaces, vars
require
to make other code available for use.
- plain maps
deftype
defrecord
- Multimethods
- user-defined dispatch - typically on values
- Protocols
- Type-based dispatch
- Can extend (closed) Java classes to participate
- clojure.test is the standard.
- some others:
- Design choices making state and concurrency easy to reason about pervade the language.
- Persistent data structures
- "Persistent" as in it always preserves previous versions of itself, not as in a database.
- STM (Software Transactional Memory)
- Lots of choices:
- Threads
- Futures
- Promises
- Agents
- pmap (parallel map)
- Reducers
- JVM platform options, e.g. executors
- core.async
- Platform interop for Java and JavaScript
- Slack - get access via clojurians.net
- IRC - on Freenode, #clojure, #clojure-beginners, #clojurescript, #clojure-emacs, ...
- Clojure Google Group
- Meetup groups:
- Denver Den of Clojure
- Boulder Clojurians
- Clojure/conj
- Clojure/west
- Strange Loop
- Links
- Repo: github.com/iantruslove/gentle-intro
- These slides: git.io/vwlpz
- Gist for slides: iantruslove/860aec352c8271e20827824ae6d1a0d0
- Ring coding idea: gistdeck.github.io/iantruslove/e72455aa468938ba78c16f29bbec8f9a#1
- Me:
You're welcome - how on earth did you stumble upon this?