Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Introduction to Clojure
1. Functional Programming on the JVM
using Clojure
Baishampayan Ghose
Infinitely Beta Technologies
GNUnify 2010
1 / 31
2. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
2 / 31
3. Who am I?
My name is BG and I am a Computer guy
FP head
Scale nerd
Prog-lang lawyer
Web standards ninja
FOSS geek
Startup-ist
3 / 31
4. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
4 / 31
5. What, why and how of Clojure
What is Clojure?
Why a new programming language?
How is Clojure any better than X?
5 / 31
6. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
6 / 31
7. Fundamentals
Clojure is a Lisp
Clojure is dynamic
Clojure is hosted on the JVM
Clojure is functional
Clojure is geared towards concurrency
Free & Open Source
7 / 31
10. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
10 / 31
11. Syntax
There is no other syntax!
Data structures are the code
No other text based syntax, just different
interpretations
There is a fancy name for this — Homoiconicity
11 / 31
12. Syntax
There is no other syntax!
Data structures are the code
No other text based syntax, just different
interpretations
There is a fancy name for this — Homoiconicity
Everything is an expression
All data literals stand for themselves, except —
Symbols
Lists
11 / 31
13. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
12 / 31
15. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
14 / 31
16. Sequences
An abstraction over traditional Lisp lists
Provides an uniform way of walking through data
structures
(seq coll)
If collection is non-empty, return a sequence object
(first s)
Return the first item
(rest s)
Return a seq of the rest of elements
15 / 31
17. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
16 / 31
18. Java Inter-op
Wrapper free interface to Java
Syntactic sugar to make Java invocation easy
Core Clojure abstractions are Java interfaces
Clojure functions implement Callable & Runnable
Clojure sequence library works on Java iterables
Easy to implement, extend Java interfaces (if
needed)
Almost identical to Java in terms of speed
17 / 31
19. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
18 / 31
21. Concurrency
Simultaneous execution
Avoid reading,yielding inconsistent data
Synchronous Asynchronous
Coordinated ref
Independent atom agent
Unshared var
Table: Building blocks of Clojure concurrency
19 / 31
22. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
20 / 31
23. Multimethods
Generalised indirect dispatch
Dispatch on a arbitrary function of the arguments
21 / 31
24. Multimethods
Generalised indirect dispatch
Dispatch on a arbitrary function of the arguments
Call sequence
Call dispatch function on args to get dispatch value
Find method associated with dispatch value
21 / 31
25. Multimethods
Generalised indirect dispatch
Dispatch on a arbitrary function of the arguments
Call sequence
Call dispatch function on args to get dispatch value
Find method associated with dispatch value
Else call default method, else error
21 / 31
26. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
22 / 31
27. There is more!
Metadata
Destructuring
Transients
Zippers
Futures, Promises
clojure.contrib
Ping me after the talk for details
23 / 31
28. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
24 / 31
34. Outline
1 Who am I?
2 What, why and how of Clojure
3 Fundamentals
4 Syntax
5 Hello, Clojure!
6 Sequences
7 Java Inter-op
8 Concurrency
9 Multimethods
10 There is more!
11 Tools
12 Resources
13 Q&A
14 Contacting me
30 / 31
35. Contacting me
http://freegeek.in/
bg@infinitelybeta.com
@ghoseb on Twitter
Slides on - http://bit.ly/gnunify-clojure
Infinitely Beta is recruiting smart hackers!
http://infinitelybeta.com/jobs/
CC BY SA
31 / 31