This document provides an overview of Clojure and why one may want to try it. Some key points include:
- Clojure is a functional programming language that runs on the JVM and allows easy interoperability with Java.
- It has a very small and elegant syntax based on Lisp with sensible macro names and prefix notation.
- Clojure encourages pure functional programming and the use of immutable data structures, while providing tools like Software Transactional Memory to allow safe mutable state changes.
- Its focus on functions as first-class citizens and referential transparency can provide benefits for writing parallel and concurrent code more easily compared to other languages.
Gen AI in Business - Global Trends Report 2024.pdf
Getting started with Clojure
1.
2. Assumptions
Some experience with Java development
Little or no experience with Clojure
You want to try something different!
Haskell, Erlang and
Scala seem hairy!
8. One of many JVM languages
Java
Groovy
Jruby
Jython
Scala
Clojure
9. A little more ubiquitous
.Net framework – DLR/CLR
In browsers > ClojureScript
Native compilers
10.
11. Very small syntax
( )
[ ]
def, defn, defproject
list, map, vector, set
let
#
_
atom
12. It uses mathematical concepts
Functions have a value
For a given set of arguments,
you should always get the same
result
(Referential transparency)
13. A better Lisp !
Sensible () usage
Sensible macro names
JVM Interoperability
Lisp is the 2nd oldest programming language still in use
25. Clojure concepts
Encourages Pure Functional approach
- use STM to change state
Functions as first class citizens
- functions as arguments as they return a value
Make JVM interoperation simple
- easy to use your existing Java applications
26. Its all byte code in the end..
Any object in Clojure is just a regular java
object
Types inherit from:
java.lang.object
45. Working with Java
Java Classes
● fullstop after class name
(JFrame. )
(Math/cos 3) ; static method call
Java methods
● fullstop before method name
(.getContentPane frame) ;;method name first
(. frame getContentPane) ;;object first
46. What class is that...
(class (str "Jr0cket"))
java.lang.String
(class (defn hello-world [name] (str "Hello
cruel world")))
clojure.lang.Var
53. Maven
Just like any other Java project
Step 1)
Add Clojure library dependency to your
POM
Step 2)
Download the Internet !!!
54. Leiningen leiningen.org
lein new ● Create a new Clojure project
lein deps ● Download all dependencies
lein repl ● Start the interactive shell (repl)
lein jack-in ● Start a REPL server
66. Recursive functions
● Functions that call ● Tail recursion
themselves ● Avoids blowing the
stack
● Fractal coding
● A trick as the JVM
does not support tail
recursion directly :-(