SlideShare a Scribd company logo
A taste of
!
!
David Leung!
!
Twitter: @davleung
Email: david@davidslab.com
GPG Fingerprint: 217E 1ECE 2349 D178 73E5 C194 1E2E C02A A74A A531
What is Clojure?
Hosted
Runs on multiple major
platforms
JVM
CLR
JS Runtime (ClojureScript)
What is Clojure?
Hosted
Excellent Interops
EXAMPLE 1
Retrieve a webpage using Java library
!
!
;;	
  Imports	
  the	
  java.net.URL	
  class	
  into	
  current	
  namespace	
  
(import	
  ‘java.net.URL)	
  
	
  	
  
;;	
  Creating	
  an	
  instance	
  of	
  URL.	
  
;;	
  In	
  Java:	
  
;;	
  	
  	
  URL	
  con	
  =	
  new	
  URL(“http://www.reddit.com”)	
  
(def	
  con	
  (URL.	
  “http://www.reddit.com”))	
  
!
!
;;	
  GET	
  the	
  page	
  and	
  print	
  it!	
  
(println	
  (slurp	
  con))
What is Clojure?
Hosted
Functional
First class functions
Build software by composing over functions
EXAMPLE 2
Applying arbitrary function to a collection of data
!
;;	
  Name	
  a	
  collection	
  of	
  numbers	
  
(def	
  data	
  [1	
  2	
  3	
  4	
  5])	
  
!
;;	
  Creates	
  a	
  function	
  called	
  process-­‐data	
  that	
  accepts	
  a	
  collection	
  and	
  an	
  operation	
  to	
  be
(defn	
  process-­‐data	
  [collection	
  operation]	
  
	
  	
  	
  	
  (apply	
  operation	
  collection))	
  
!
;;	
  Addition	
  
(process-­‐data	
  data	
  +)	
  
!
;;	
  Multiplication	
  
(process-­‐data	
  data	
  *)	
  
!
Relax if you aren’t following the syntax :-)
You’ll learn this in the workshop
What is Clojure?
Hosted
Functional
Immutability
Easy Reasoning and Debugging
In the following Ruby code, can you be sure
that x is not modified?
!
x	
  =	
  {problems:	
  99}	
  
!
dodgyMethod(x);	
  
!
#	
  what	
  is	
  the	
  value	
  of	
  x?	
  
x[":problems"]	
  
What is Clojure?
Hosted
Functional
Immutability
Separation of Identity & State
!
Identity is a reference to something.
State is the aggregated values of an identity
at a particular point in time.
In Clojure, an identity’s state is updated by
creating a new value and assign it back to the
identify.
!
Whaaaaat? Isn’t that inefficient???
What is Clojure?
Hosted
Functional
Immutability
Efficient Structure Sharing
!
Let’s create a hash:
!(def	
  a	
  {:a	
  5	
  :b	
  6	
  :c	
  7	
  :d	
  8})	
  
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
Credit: Image from “Clojure Programming” by Chas Emerick, Brian Carper & Christophe Grand
What is Clojure?
Hosted
Functional
Immutability
Efficient Structure Sharing
!
!(def	
  a	
  {:a	
  5	
  :b	
  6	
  :c	
  7	
  :d	
  8})	
  
!
(def	
  b	
  (assoc	
  a	
  :c	
  0))	
  
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
“Copying” data is cheap!
!
!
!
Credit: Image from “Clojure Programming” by Chas Emerick, Brian Carper & Christophe Grand
What is Clojure?
Hosted
Functional
Immutability
Fosters Concurrent Programming
!
“Immutable objects are always
thread safe.”
—Brian Goetz

(Author of Java Concurrency in Practice)
!
!
!
More about Concurrency later
What is Clojure?
Hosted
Functional
Parallelism
Parallel processing
Trivial Parallel Processing Problem
Problem	 The Boss just asked you to parse
100K serialized JSON objects into a hash.
Each string is ~300KB.
The collection/array of strings are stored in
the variable problemsCollection.
!
Write a snippet that makes use of all cores to process
this collection. Don’t worry about storing the result.
!
Do this within a minute, or you are fired.
!
Time starts now.
What is Clojure?
Hosted
Functional
Parallelism
Parallel processing
Trivial Parallel Processing Problem
Solution
!
!
;;	
  non-­‐parallelized	
  version	
  that	
  will	
  get	
  you	
  fired	
  
(dorun	
  (map	
  json/read-­‐str	
  problemsCollection))	
  
!
;;	
  parallelized	
  version	
  
(dorun	
  (pmap	
  json/read-­‐str	
  problemsCollection))	
  
!
!
EXAMPLE 3 (DEMO)
!
Note	 pmap is a parallelized version of map
What is Clojure?
Hosted
Functional
Parallelism
Parallel processing
Watch out for the overhead involved in
distributing work to the work!
!
EXAMPLE 4 (DEMO)
!
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Two types of

Concurrent Operations
Coordinated Concurrency
One or more actors (threads) must coordinate
to produce the right computation.
e.g. Bank transactions
!
Synchronous Concurrency
Should the thread that wants to update a
reference be blocked until their return?
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
3 flavors of Reference
Types
Coordinated Uncoordinated
Synchronous Refs Atoms
Asynchronous Agents
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Atoms
Create an atom
(def	
  counter	
  
	
  	
  	
  	
  (atom	
  0))	
  
Access an atom’s value (dereferencing)
(deref	
  counter)	
  
!
;;	
  syntactical	
  sugar	
  
@counter	
  
Compare and Swap
(swap!	
  counter	
  +	
  2)	
  
!
Note:	 Clojure uses ! in a function’s name to
	 	 denote that the function mutates 	
	 	 state (memory/IO).
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Software Transactional
Memory (STM)
STM: Database-like Transactions for Concurrency
!
Clojure controls updates to references via a system
called STM. It removes the need for manual locking.
!
!
!
!
!
Fulfills the Atomicity, Consistency, and Isolation
aspects of the Database Transaction Properties ACID.
STM is to concurrency
what
Garbage Collector is to memory management
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Software Transactional
Memory (STM)
There are more to concurrency
Clojure has “data flow variables” too!
We’ll cover concurrency in the workshops
later. Things we will look at:
!
Future
Delay
Promise
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
What is a Lisp?
!
!
!
!
!
!
Lisp is invented by John McCarthy in 1958.
Lisp pioneered ideas like tree data structures,
dynamic typing, garbage collection, higher-
order functions, recursion.
John McCarthy is quite the hero in Computer
Science.
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Lisp: LISt Processing
Lisp is written in symbolic expressions, or S-
expressions.
S-expressions are written as a pair of parenthesis
surrounding a sequence of symbols:
(f a b c)
!
The first position in the list is also known as the
functional position. When evaluated, the function f will
be called with the rest of the list as arguments.
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Collection Types
Collection types in Clojure
!
List		 (a b c d e)	 	 Essentially a linked list
Vector	 [a b c d e]	 	 Like “arrays” in Ruby/Python
!
Wait a second…
Didn’t we already see those square brackets and
parentheses when we define a function?
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Homoiconicity
Homoiconicity
Lisp is a language where the structure of the code is
represented by standard data structures (list, vectors,
hash).
Repeat after me
!
Code as Data. Data as Code.
!
!
(defn	
  wont-­‐make-­‐you-­‐blind	
  [name]	
  
	
  	
  (println	
  name	
  ",	
  parentheses	
  won't	
  make	
  you	
  
blind"))
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Homoiconicity
Construct a function call with collection manipulation
functions
!
;;	
  the	
  quotation	
  mark	
  stops	
  Clojure	
  treating	
  the	
  
;;	
  list	
  as	
  a	
  function	
  call	
  
(def	
  arguments	
  '(1	
  2	
  3))	
  
!
;;	
  cons	
  is	
  a	
  traditional	
  lisp	
  function	
  
;;	
  that	
  prepends	
  an	
  object	
  to	
  the	
  head	
  of	
  a	
  list	
  
(def	
  function-­‐call	
  (cons	
  +	
  arguments))	
  
!
(eval	
  function-­‐call)	
  
;;	
  =>	
  6	
  
!
!
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Macros
Building Malleable Systems
!
As well as being able to write code that “writes
code” (metaprogramming), you can even change the
evaluation semantics by writing macros!
We’ll explore this in the workshops.
What is Clojure?
Hosted
Functional
Parallelism
Concurrency
Lisp
Language Extensions
The flexible of Clojure allows Clojure and your
codebase to stretch and bend to your needs.
Notable Clojure extensions:
!
core.async	 	 	 Implementation of channels and
	 	 	 	 	 blocks from the Go programming
	 	 	 	 	 language.
core.logic	 	 	 Implementation of miniKanren for
	 	 	 	 	 doing relational/constraint logic
	 	 	 	 	 programming.
core.typed	 	 	 Optional typing for Clojure.
Working with Clojure
Editors
!
emacs
Light Table
VimClojure
CounterClockWise (eclipse)
IntelliJ
Working with Clojure
Build Tools
!
	

 	

 	

 	

 	

 Leiningen	

	

 	

 	

 	

 	

 for automating Clojure projects without setting your hair on fire	

	

 	

 	

 	

 	

 	

	

 	

 	

 	

 	

 	

	

 	

 	

 	

 	

 http://leiningen.org	

!
ht
Working with Clojure
Learning Resources
	

 	

 	

 	

 	

 	

Test Driven Learning
	 4Clojure	 	 	 	 4clojure.com
	 Clojure Koans		 	 clojurekoans.com
!
Books
	 Clojure Programming
	 Joy of Clojure Second Edition
	 Clojure Cookbook
Working with Clojure
!
!
David Leung!
!
Twitter: @davleung
Email: david@davidslab.com
GPG Fingerprint: 217E 1ECE 2349 D178 73E5 C194 1E2E C02A A74A A531

More Related Content

KEY
A million connections and beyond - Node.js at scale
PDF
Clojure, Plain and Simple
KEY
JavaOne 2011 - JVM Bytecode for Dummies
PDF
Exploring Clojurescript
PPTX
Node.js Workshop - Sela SDP 2015
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
PDF
Fun with Functional Programming in Clojure
PDF
The Year of JRuby - RubyC 2018
A million connections and beyond - Node.js at scale
Clojure, Plain and Simple
JavaOne 2011 - JVM Bytecode for Dummies
Exploring Clojurescript
Node.js Workshop - Sela SDP 2015
Asynchronous I/O in NodeJS - new standard or challenges?
Fun with Functional Programming in Clojure
The Year of JRuby - RubyC 2018

What's hot (20)

KEY
CoffeeScript By Example
PPTX
Node.js: A Guided Tour
PDF
Quick Introduction to Kotlin Coroutine for Android Dev
PDF
Connecting the Worlds of Java and Ruby with JRuby
PPTX
Java Serialization Facts and Fallacies
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
PDF
Clojure made-simple - John Stevenson
PDF
Zen of Akka
PDF
Clojure for Java developers
PDF
Node Architecture and Getting Started with Express
PDF
Understanding the Single Thread Event Loop
PDF
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
PDF
Building Fast, Modern Web Applications with Node.js and CoffeeScript
PDF
Introduction to clojure
PDF
Kotlin - Better Java
KEY
Introduction to node.js
PPTX
Node.js Patterns for Discerning Developers
PDF
Kotlin @ Coupang Backend 2017
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PDF
Multithreading and Parallelism on iOS [MobOS 2013]
CoffeeScript By Example
Node.js: A Guided Tour
Quick Introduction to Kotlin Coroutine for Android Dev
Connecting the Worlds of Java and Ruby with JRuby
Java Serialization Facts and Fallacies
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Clojure made-simple - John Stevenson
Zen of Akka
Clojure for Java developers
Node Architecture and Getting Started with Express
Understanding the Single Thread Event Loop
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Building Fast, Modern Web Applications with Node.js and CoffeeScript
Introduction to clojure
Kotlin - Better Java
Introduction to node.js
Node.js Patterns for Discerning Developers
Kotlin @ Coupang Backend 2017
Original slides from Ryan Dahl's NodeJs intro talk
Multithreading and Parallelism on iOS [MobOS 2013]
Ad

Viewers also liked (6)

PDF
Hopper Elasticsearch Hackathon
PPTX
Boston elasticsearch meetup October 2012
PDF
Elasticsearch Quick Introduction
PPTX
Real time analytics using Hadoop and Elasticsearch
PDF
Business Transformation: PwC Presents Its Viewpoint on the Integration Fabric
PDF
Combine Apache Hadoop and Elasticsearch to Get the Most of Your Big Data
Hopper Elasticsearch Hackathon
Boston elasticsearch meetup October 2012
Elasticsearch Quick Introduction
Real time analytics using Hadoop and Elasticsearch
Business Transformation: PwC Presents Its Viewpoint on the Integration Fabric
Combine Apache Hadoop and Elasticsearch to Get the Most of Your Big Data
Ad

Similar to A Taste of Clojure (20)

PDF
Functional web with clojure
PPTX
Clojure Fundamentals Course For Beginners
PDF
Clojure and The Robot Apocalypse
ODP
Getting started with Clojure
KEY
The Why and How of Scala at Twitter
PDF
Get into Functional Programming with Clojure
PDF
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
PPTX
All of javascript
PPTX
Modern JavaScript Development @ DotNetToscana
PDF
Building Concurrent WebObjects applications with Scala
PPTX
All of Javascript
PDF
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
PDF
Introduction to Clojure
PDF
Play framework
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PDF
Zepto and the rise of the JavaScript Micro-Frameworks
ODP
Clojure
PDF
Raffaele Rialdi
PPTX
Scripting as a Second Language
Functional web with clojure
Clojure Fundamentals Course For Beginners
Clojure and The Robot Apocalypse
Getting started with Clojure
The Why and How of Scala at Twitter
Get into Functional Programming with Clojure
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
All of javascript
Modern JavaScript Development @ DotNetToscana
Building Concurrent WebObjects applications with Scala
All of Javascript
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
Introduction to Clojure
Play framework
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Zepto and the rise of the JavaScript Micro-Frameworks
Clojure
Raffaele Rialdi
Scripting as a Second Language

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Understanding_Digital_Forensics_Presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
MYSQL Presentation for SQL database connectivity
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

A Taste of Clojure

  • 1. A taste of ! ! David Leung! ! Twitter: @davleung Email: david@davidslab.com GPG Fingerprint: 217E 1ECE 2349 D178 73E5 C194 1E2E C02A A74A A531
  • 2. What is Clojure? Hosted Runs on multiple major platforms JVM CLR JS Runtime (ClojureScript)
  • 3. What is Clojure? Hosted Excellent Interops EXAMPLE 1 Retrieve a webpage using Java library ! ! ;;  Imports  the  java.net.URL  class  into  current  namespace   (import  ‘java.net.URL)       ;;  Creating  an  instance  of  URL.   ;;  In  Java:   ;;      URL  con  =  new  URL(“http://www.reddit.com”)   (def  con  (URL.  “http://www.reddit.com”))   ! ! ;;  GET  the  page  and  print  it!   (println  (slurp  con))
  • 4. What is Clojure? Hosted Functional First class functions Build software by composing over functions EXAMPLE 2 Applying arbitrary function to a collection of data ! ;;  Name  a  collection  of  numbers   (def  data  [1  2  3  4  5])   ! ;;  Creates  a  function  called  process-­‐data  that  accepts  a  collection  and  an  operation  to  be (defn  process-­‐data  [collection  operation]          (apply  operation  collection))   ! ;;  Addition   (process-­‐data  data  +)   ! ;;  Multiplication   (process-­‐data  data  *)   ! Relax if you aren’t following the syntax :-) You’ll learn this in the workshop
  • 5. What is Clojure? Hosted Functional Immutability Easy Reasoning and Debugging In the following Ruby code, can you be sure that x is not modified? ! x  =  {problems:  99}   ! dodgyMethod(x);   ! #  what  is  the  value  of  x?   x[":problems"]  
  • 6. What is Clojure? Hosted Functional Immutability Separation of Identity & State ! Identity is a reference to something. State is the aggregated values of an identity at a particular point in time. In Clojure, an identity’s state is updated by creating a new value and assign it back to the identify. ! Whaaaaat? Isn’t that inefficient???
  • 7. What is Clojure? Hosted Functional Immutability Efficient Structure Sharing ! Let’s create a hash: !(def  a  {:a  5  :b  6  :c  7  :d  8})   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! Credit: Image from “Clojure Programming” by Chas Emerick, Brian Carper & Christophe Grand
  • 8. What is Clojure? Hosted Functional Immutability Efficient Structure Sharing ! !(def  a  {:a  5  :b  6  :c  7  :d  8})   ! (def  b  (assoc  a  :c  0))   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! “Copying” data is cheap! ! ! ! Credit: Image from “Clojure Programming” by Chas Emerick, Brian Carper & Christophe Grand
  • 9. What is Clojure? Hosted Functional Immutability Fosters Concurrent Programming ! “Immutable objects are always thread safe.” —Brian Goetz
 (Author of Java Concurrency in Practice) ! ! ! More about Concurrency later
  • 10. What is Clojure? Hosted Functional Parallelism Parallel processing Trivial Parallel Processing Problem Problem The Boss just asked you to parse 100K serialized JSON objects into a hash. Each string is ~300KB. The collection/array of strings are stored in the variable problemsCollection. ! Write a snippet that makes use of all cores to process this collection. Don’t worry about storing the result. ! Do this within a minute, or you are fired. ! Time starts now.
  • 11. What is Clojure? Hosted Functional Parallelism Parallel processing Trivial Parallel Processing Problem Solution ! ! ;;  non-­‐parallelized  version  that  will  get  you  fired   (dorun  (map  json/read-­‐str  problemsCollection))   ! ;;  parallelized  version   (dorun  (pmap  json/read-­‐str  problemsCollection))   ! ! EXAMPLE 3 (DEMO) ! Note pmap is a parallelized version of map
  • 12. What is Clojure? Hosted Functional Parallelism Parallel processing Watch out for the overhead involved in distributing work to the work! ! EXAMPLE 4 (DEMO) !
  • 13. What is Clojure? Hosted Functional Parallelism Concurrency Two types of
 Concurrent Operations Coordinated Concurrency One or more actors (threads) must coordinate to produce the right computation. e.g. Bank transactions ! Synchronous Concurrency Should the thread that wants to update a reference be blocked until their return?
  • 14. What is Clojure? Hosted Functional Parallelism Concurrency 3 flavors of Reference Types Coordinated Uncoordinated Synchronous Refs Atoms Asynchronous Agents
  • 15. What is Clojure? Hosted Functional Parallelism Concurrency Atoms Create an atom (def  counter          (atom  0))   Access an atom’s value (dereferencing) (deref  counter)   ! ;;  syntactical  sugar   @counter   Compare and Swap (swap!  counter  +  2)   ! Note: Clojure uses ! in a function’s name to denote that the function mutates state (memory/IO).
  • 16. What is Clojure? Hosted Functional Parallelism Concurrency Software Transactional Memory (STM) STM: Database-like Transactions for Concurrency ! Clojure controls updates to references via a system called STM. It removes the need for manual locking. ! ! ! ! ! Fulfills the Atomicity, Consistency, and Isolation aspects of the Database Transaction Properties ACID. STM is to concurrency what Garbage Collector is to memory management
  • 17. What is Clojure? Hosted Functional Parallelism Concurrency Software Transactional Memory (STM) There are more to concurrency Clojure has “data flow variables” too! We’ll cover concurrency in the workshops later. Things we will look at: ! Future Delay Promise
  • 18. What is Clojure? Hosted Functional Parallelism Concurrency Lisp What is a Lisp? ! ! ! ! ! ! Lisp is invented by John McCarthy in 1958. Lisp pioneered ideas like tree data structures, dynamic typing, garbage collection, higher- order functions, recursion. John McCarthy is quite the hero in Computer Science.
  • 19. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Lisp: LISt Processing Lisp is written in symbolic expressions, or S- expressions. S-expressions are written as a pair of parenthesis surrounding a sequence of symbols: (f a b c) ! The first position in the list is also known as the functional position. When evaluated, the function f will be called with the rest of the list as arguments.
  • 20. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Collection Types Collection types in Clojure ! List (a b c d e) Essentially a linked list Vector [a b c d e] Like “arrays” in Ruby/Python ! Wait a second… Didn’t we already see those square brackets and parentheses when we define a function?
  • 21. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Homoiconicity Homoiconicity Lisp is a language where the structure of the code is represented by standard data structures (list, vectors, hash). Repeat after me ! Code as Data. Data as Code. ! ! (defn  wont-­‐make-­‐you-­‐blind  [name]      (println  name  ",  parentheses  won't  make  you   blind"))
  • 22. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Homoiconicity Construct a function call with collection manipulation functions ! ;;  the  quotation  mark  stops  Clojure  treating  the   ;;  list  as  a  function  call   (def  arguments  '(1  2  3))   ! ;;  cons  is  a  traditional  lisp  function   ;;  that  prepends  an  object  to  the  head  of  a  list   (def  function-­‐call  (cons  +  arguments))   ! (eval  function-­‐call)   ;;  =>  6   ! !
  • 23. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Macros Building Malleable Systems ! As well as being able to write code that “writes code” (metaprogramming), you can even change the evaluation semantics by writing macros! We’ll explore this in the workshops.
  • 24. What is Clojure? Hosted Functional Parallelism Concurrency Lisp Language Extensions The flexible of Clojure allows Clojure and your codebase to stretch and bend to your needs. Notable Clojure extensions: ! core.async Implementation of channels and blocks from the Go programming language. core.logic Implementation of miniKanren for doing relational/constraint logic programming. core.typed Optional typing for Clojure.
  • 25. Working with Clojure Editors ! emacs Light Table VimClojure CounterClockWise (eclipse) IntelliJ
  • 26. Working with Clojure Build Tools ! Leiningen for automating Clojure projects without setting your hair on fire http://leiningen.org ! ht
  • 27. Working with Clojure Learning Resources Test Driven Learning 4Clojure 4clojure.com Clojure Koans clojurekoans.com ! Books Clojure Programming Joy of Clojure Second Edition Clojure Cookbook
  • 28. Working with Clojure ! ! David Leung! ! Twitter: @davleung Email: david@davidslab.com GPG Fingerprint: 217E 1ECE 2349 D178 73E5 C194 1E2E C02A A74A A531