SlideShare a Scribd company logo
One of the Most Popular Course on Clojure -
Clojure Fundamentals For Beginners
Write shorter codes that do so much more with
Clojure. Clojure is the perfect blend of a
general-purpose programming language and a
functional programming language. Created by
Rich Hickey, the programming language
combines the interactive development of a
scripting language with that of a robust
infrastructure for multi-threading programming.
This course covers the fundamentals of Clojure
as well as teach you how to start coding using
the language. The following slides will let you
know, all that the course encompasses.
Clojure and Java
Clojure runs on the JVM.
Java is an incredibly verbose language that has only limited support for functions
via lambda’s
Clojure is an incredibly terse language
By incorporating Clojure into Java code we can greatly reduce the verbosity and allow important
functional tools like recursion
By incorporating Java into Clojure code allows use of Java’s extensive native functionality and
its enormous ecosystem
The ability to use Java classes, objects, and methods is called Java interop
http://clojure.org/reference/java_interop
Clojure and JavaScript
Developers don't just write assembly to write a desktop applications it is just not feasable.
JavaScript is ubiquitous.
Developers use compilers to take a high level language to assembly
Is Javascript like the assembly language of the web.
Javascript is a high-level, dynamic language
Writing high-performance JavaScript is a challenge
Javascript does not really have shared memory model, it has webworkers
can only pass very limited set of data, strings or JSON objects
By using Compilers we can take JavaScript to output JavaScript as properly formed and
otherwise cross-browser compatible code
Clojure Application Packaging
Software Engineering Build Tools
compiling computer source code into binary code
packaging binary code
running tests
deployment to production systems
creating documentation and/or release notes
Uber Jar
Package your Clojure project into one self-contained file. (a Java “uber” jar file.)
The JVM has a classloader, which takes the compiled bytecode and loads it into the running
JVM. If the byte code for your dependencies is not available at runtime then your application
fails with a “class not found exception”.
“Uber jar” is a jar file of all Clojure source code compiled to bytecode and all the projects
dependencies.
Clojure Functions
Function defn
( defn square [x] ( * x x))
https://clojuredocs.org/clojure.core/range
( range 10)
Higher order function ‘map‘
(map square ( range 10) )
Core functions data flow for expressions
Core function = str
(def myMap {:firstKey "firstValue", :secKey "secValue"})
(str "first key value: " (:firstKey myMap ) " second key value: " (:secKey myMap ))
Higher order function ‘apply ‘
(apply str [ "one" "two" "three" ]) is the same as : (str "one" "two" "three")
(str [ "one" "two" "three" ])
Clojure Macros
Macros use the source code as data (input) like functions use data
"thread-first" macro
(-> "first" (str " last"))
(str "first" " last")
"thread-last" macro
(->> " last" (str " first"))
Thread macro takes an expression to a form f(source code) -> source code
‘->’ : “term” ===> Form
‘-->’ : “term” ===> Form
inserts the first term as the first /last item in second form
inserts the first form as the first /last item in second form
Clojure Memory Model
Clojure is a dialect of Lisp that runs on the JVM.
(Common Language Runtime (like JVM) and Javascript engines)
Objectives
What is a memory model why is it needed
JMM what is it how does it work
STM what is it how does it work
Clojure Process core-async
Summary Clojure Concurrency
Vars
Immutable by default
Mutable call dynamic (def ^:dynamic *my-str-type*
"mutable variable")
As a mutable variable have thread local scope
(visibility)
Atoms
Are visible (synchronised)
(def my-atom (atom 10)) de-reference @my-atom
(reset! my-atom 12) functional (swap! my-atom
update )
Use swap! in STM block
STM
Refs
Agents
Refs
ACID Transcational Atoms
Update with alter in synchronised block
(dosync (translate-point ))
Agents
Refs that update asynchronously (def
my-agent (agent 10))
No strict consistency for reads
(send my-agent update-my-agent)
Clojure Web Applications
Ring is a Clojure web applications library inspired by Python's WSGI and Ruby's Rack
Compojure is a rest api for rapid development of web applications in Clojure
https://github.com/weavejester/compojure
In compojure, each route is an HTTP method paired with a URL-matching pattern
Compojure route definitions are just functions configured for Ring (accept request
maps and return response maps)
1. Use a template lein new compojure eddy_comp
2. run the Ring web server lein ring server
3. defroutes site-defaults src/eddy_compjure/handler.clj
4. :keys :plugins :ring project.clj
5. Access the context root localhost:3000
6. JSON https://github.com/dakrone/cheshire
7. ClojureScript configuration
8. ClojureScript rest client
Functional Composition
Arity
arity 2
(def make-a-set
(fn ([x] #{x})
([x y] #{x y})))
(make-a-set 1)
(make-a-set 1 2)
Variadic functions
(defn var-args [x & rest] (apply str
(butlast rest) ) )
(var-args 0 1 2 3 4)
Currying
Currying is a way to generate a new function with an
argument partially applied
partial is a way of currying
partial
https://clojuredocs.org/clojure.core/partial
(def make-a-set (fn ([x y] #{x y})))
( (partial make-a-set 2) 3 )
What if we want to create a function not just a form
(def make-a-set-5 (partial make-a-set 5))
(make-a-set-5 10)
Clojure Concurrent tools: Atoms, Refs, Vars
Objectives
1. What is a memory model why is it needed
2. JMM what is it how does it work
3. STM what is it how does it work
Result
1. memory model is a set of rules implemented in hardware and software that controls
the way variables are updated during program execution by multiple threads of
execution
2. Java memory model (JMM) is a set of low level concurrency artifacts (locks, atomic
variables and synchronisation(visibility) ) combined with high level frameworks
(Executor Service, Futures, ForkJoin, …...) to implement a memory model.
3. Software Transactional Memory (STM) an ACID transactional system for how a
variable that is shared between threads updates, STM is implemented with the low
Functional recipe: Pure functions with Immutable Data Structures
Pure Functions
Side effects = changes that functions make in addition to their return value
Pure functions do not depend on external data sources and do not provoke side effects of any kind.
When invoked with a set of arguments, will always respond with
the same return value
Higher-Order Functions
● Takes one or more functions as arguments
● Returns a function as a result
Clojure has families of higher order functions <==> Clojure Abstractions
Eg sequence functions map reduce filter
sequence <==> Data Structure Abstraction {sequence}
Gradle Environment
1 install gradle
.bashrc
export GRADLE_HOME=/home/ubu/gradle
export PATH=$PATH:$GRADLE_HOME/bin
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
.bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export GRADLE_HOME=/home/ubu/gradle
export PATH=$PATH:$GRADLE_HOME/bin
source .bashrc
Leiningen Environment
Software Engineering Build Tools
Compiling computer source code into binary code
Packaging binary code
Running tests
Deployment to production systems
Creating documentation and/or release notes
Objectives
1. Install leningen
2. Understand Leiningen project layout
3. Understand Leiningen build script (dependencies ect ..)
4. Run the clojure repl
Functional Recursive Data Flow
Recursion is one of the fundamental techniques
used in functional programming.
Review
Function literal
((fn [x y] #{x y}) 1 2)
Function arity 2
(def make-a-set
(fn ([x] #{x})
([x y] #{x y})))
(make-a-set 1)
(make-a-set 1 2)
def special form is a way to assign a symbolic name to a piece of Clojure data
www.eduonix.com
https://www.eduonix.com/courses/Software-Development/clojure-fundamentals-for-beginners

More Related Content

What's hot (20)

PPT
iOS Multithreading
Richa Jain
 
PDF
Java Concurrency in Practice
Alina Dolgikh
 
PPTX
Unit1 introduction to Java
DevaKumari Vijay
 
PPT
Basic java part_ii
Khaled AlGhazaly
 
PPTX
Build, logging, and unit test tools
Allan Huang
 
PDF
Introduction to the Java bytecode - So@t - 20130924
yohanbeschi
 
ODP
Java Concurrency, Memory Model, and Trends
Carol McDonald
 
PDF
Clojure, Plain and Simple
Ben Mabey
 
PPTX
Basics of Java Concurrency
kshanth2101
 
PDF
Java Course 10: Threads and Concurrency
Anton Keks
 
PPTX
Java concurrency - Thread pools
maksym220889
 
KEY
Threading in iOS / Cocoa Touch
mobiledeveloperpl
 
PPTX
Java bytecode and classes
yoavwix
 
PDF
Java Multithreading Using Executors Framework
Arun Mehra
 
PPTX
The Java memory model made easy
Rafael Winterhalter
 
PDF
Loom and concurrency latest
Srinivasan Raghavan
 
PDF
Java Programming - 01 intro to java
Danairat Thanabodithammachari
 
KEY
Grand Central Dispatch Design Patterns
Robert Brown
 
PDF
Multithreading in Java
Appsterdam Milan
 
iOS Multithreading
Richa Jain
 
Java Concurrency in Practice
Alina Dolgikh
 
Unit1 introduction to Java
DevaKumari Vijay
 
Basic java part_ii
Khaled AlGhazaly
 
Build, logging, and unit test tools
Allan Huang
 
Introduction to the Java bytecode - So@t - 20130924
yohanbeschi
 
Java Concurrency, Memory Model, and Trends
Carol McDonald
 
Clojure, Plain and Simple
Ben Mabey
 
Basics of Java Concurrency
kshanth2101
 
Java Course 10: Threads and Concurrency
Anton Keks
 
Java concurrency - Thread pools
maksym220889
 
Threading in iOS / Cocoa Touch
mobiledeveloperpl
 
Java bytecode and classes
yoavwix
 
Java Multithreading Using Executors Framework
Arun Mehra
 
The Java memory model made easy
Rafael Winterhalter
 
Loom and concurrency latest
Srinivasan Raghavan
 
Java Programming - 01 intro to java
Danairat Thanabodithammachari
 
Grand Central Dispatch Design Patterns
Robert Brown
 
Multithreading in Java
Appsterdam Milan
 

Viewers also liked (18)

PDF
autocad_lt_2005_biblia_minta
Krist P
 
PDF
Critical Thinking like a breeze
Ahmed Reda Kraiz
 
PPT
Cbse school in abu dhabi
GIIS AbuDhabi
 
PDF
Owuor African
Charles Owuor
 
PDF
“An Assessment of Voltage Stability based on Line Voltage Stability Indices a...
iosrjce
 
PPT
Freddah M
KhensaniPrimarySchool
 
PPT
eTrøndelag
SKILLS+ project
 
PPT
MAIChem - The Indexing Solution for Chemical and Pharmaceutical Data
Access Innovations, Inc.
 
PPTX
Torq bak overview presentation from infographic
Nick Sharples
 
PPSX
Group Communication
Sara Spahić
 
PDF
Famine in somalia
Hectorgutierrez2016
 
PDF
TVSCA 2008
Paul Tate
 
PPTX
Is Accounting just for Compliance?
Joyce Lim
 
PDF
KR Workshop 1 - Ontologies
Michele Pasin
 
PDF
ICT Sector Assessment, Free Trade Agreement Signature, IESC, USAID
Mehdi Sif
 
PPTX
The basics of purchasing
Fiezha 1401
 
PDF
XPDS16: Patch review for non-maintainers - George Dunlap, Citrix Systems R&D...
The Linux Foundation
 
PDF
Building 3D Morphable Models from 2D Images
Shanglin Yang
 
autocad_lt_2005_biblia_minta
Krist P
 
Critical Thinking like a breeze
Ahmed Reda Kraiz
 
Cbse school in abu dhabi
GIIS AbuDhabi
 
Owuor African
Charles Owuor
 
“An Assessment of Voltage Stability based on Line Voltage Stability Indices a...
iosrjce
 
eTrøndelag
SKILLS+ project
 
MAIChem - The Indexing Solution for Chemical and Pharmaceutical Data
Access Innovations, Inc.
 
Torq bak overview presentation from infographic
Nick Sharples
 
Group Communication
Sara Spahić
 
Famine in somalia
Hectorgutierrez2016
 
TVSCA 2008
Paul Tate
 
Is Accounting just for Compliance?
Joyce Lim
 
KR Workshop 1 - Ontologies
Michele Pasin
 
ICT Sector Assessment, Free Trade Agreement Signature, IESC, USAID
Mehdi Sif
 
The basics of purchasing
Fiezha 1401
 
XPDS16: Patch review for non-maintainers - George Dunlap, Citrix Systems R&D...
The Linux Foundation
 
Building 3D Morphable Models from 2D Images
Shanglin Yang
 
Ad

Similar to Clojure Fundamentals Course For Beginners (20)

PDF
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion
 
PDF
Clojure made-simple - John Stevenson
JAX London
 
PDF
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
PPT
Object Oriented Methodology in Java (Lecture-1)
Md. Mujahid Islam
 
PDF
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
PPTX
brief introduction to core java programming.pptx
ansariparveen06
 
PDF
Java 8 Overview
Nicola Pedot
 
PDF
Clojure and The Robot Apocalypse
elliando dias
 
PPT
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
PPTX
It pro dev_birbilis_20101127_en
George Birbilis
 
PPT
React native
Mohammed El Rafie Tarabay
 
PDF
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
John Stevenson
 
PPTX
Java se7 features
Kumaraswamy M
 
PDF
JavaScript Miller Columns
Jonathan Fine
 
PDF
Signal Framework
Aurora Softworks
 
PDF
Clojure for Java developers
John Stevenson
 
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PriyanshuGupta101797
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion
 
Clojure made-simple - John Stevenson
JAX London
 
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
Object Oriented Methodology in Java (Lecture-1)
Md. Mujahid Islam
 
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
brief introduction to core java programming.pptx
ansariparveen06
 
Java 8 Overview
Nicola Pedot
 
Clojure and The Robot Apocalypse
elliando dias
 
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
It pro dev_birbilis_20101127_en
George Birbilis
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
John Stevenson
 
Java se7 features
Kumaraswamy M
 
JavaScript Miller Columns
Jonathan Fine
 
Signal Framework
Aurora Softworks
 
Clojure for Java developers
John Stevenson
 
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PriyanshuGupta101797
 
Ad

More from Paddy Lock (13)

PDF
An Inforgraphic to Learn React Native
Paddy Lock
 
ODP
An Introduction to Vuejs
Paddy Lock
 
ODP
Docker for Professionals: The Practical Guide
Paddy Lock
 
PDF
Getting started with React and Redux
Paddy Lock
 
PPTX
Beginners Guide to Modeling with Maya
Paddy Lock
 
PPTX
Introduction to Redis
Paddy Lock
 
PPTX
PPT on Angular 2 Development Tutorial
Paddy Lock
 
PPTX
PPT on Photoshop
Paddy Lock
 
PPTX
Advance Javascript for Coders
Paddy Lock
 
PPTX
A Complete Guide For Effective Business Communication – A Course from Eduonix
Paddy Lock
 
PPTX
Linux Administrator - The Linux Course on Eduonix
Paddy Lock
 
PDF
Infographic on Scala Programming Language
Paddy Lock
 
PPTX
Presentation on Eduonix
Paddy Lock
 
An Inforgraphic to Learn React Native
Paddy Lock
 
An Introduction to Vuejs
Paddy Lock
 
Docker for Professionals: The Practical Guide
Paddy Lock
 
Getting started with React and Redux
Paddy Lock
 
Beginners Guide to Modeling with Maya
Paddy Lock
 
Introduction to Redis
Paddy Lock
 
PPT on Angular 2 Development Tutorial
Paddy Lock
 
PPT on Photoshop
Paddy Lock
 
Advance Javascript for Coders
Paddy Lock
 
A Complete Guide For Effective Business Communication – A Course from Eduonix
Paddy Lock
 
Linux Administrator - The Linux Course on Eduonix
Paddy Lock
 
Infographic on Scala Programming Language
Paddy Lock
 
Presentation on Eduonix
Paddy Lock
 

Recently uploaded (20)

PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Difference between write and update in odoo 18
Celine George
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Introduction to Indian Writing in English
Trushali Dodiya
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 

Clojure Fundamentals Course For Beginners

  • 1. One of the Most Popular Course on Clojure - Clojure Fundamentals For Beginners Write shorter codes that do so much more with Clojure. Clojure is the perfect blend of a general-purpose programming language and a functional programming language. Created by Rich Hickey, the programming language combines the interactive development of a scripting language with that of a robust infrastructure for multi-threading programming. This course covers the fundamentals of Clojure as well as teach you how to start coding using the language. The following slides will let you know, all that the course encompasses.
  • 2. Clojure and Java Clojure runs on the JVM. Java is an incredibly verbose language that has only limited support for functions via lambda’s Clojure is an incredibly terse language By incorporating Clojure into Java code we can greatly reduce the verbosity and allow important functional tools like recursion By incorporating Java into Clojure code allows use of Java’s extensive native functionality and its enormous ecosystem The ability to use Java classes, objects, and methods is called Java interop http://clojure.org/reference/java_interop
  • 3. Clojure and JavaScript Developers don't just write assembly to write a desktop applications it is just not feasable. JavaScript is ubiquitous. Developers use compilers to take a high level language to assembly Is Javascript like the assembly language of the web. Javascript is a high-level, dynamic language Writing high-performance JavaScript is a challenge Javascript does not really have shared memory model, it has webworkers can only pass very limited set of data, strings or JSON objects By using Compilers we can take JavaScript to output JavaScript as properly formed and otherwise cross-browser compatible code
  • 4. Clojure Application Packaging Software Engineering Build Tools compiling computer source code into binary code packaging binary code running tests deployment to production systems creating documentation and/or release notes Uber Jar Package your Clojure project into one self-contained file. (a Java “uber” jar file.) The JVM has a classloader, which takes the compiled bytecode and loads it into the running JVM. If the byte code for your dependencies is not available at runtime then your application fails with a “class not found exception”. “Uber jar” is a jar file of all Clojure source code compiled to bytecode and all the projects dependencies.
  • 5. Clojure Functions Function defn ( defn square [x] ( * x x)) https://clojuredocs.org/clojure.core/range ( range 10) Higher order function ‘map‘ (map square ( range 10) ) Core functions data flow for expressions Core function = str (def myMap {:firstKey "firstValue", :secKey "secValue"}) (str "first key value: " (:firstKey myMap ) " second key value: " (:secKey myMap )) Higher order function ‘apply ‘ (apply str [ "one" "two" "three" ]) is the same as : (str "one" "two" "three") (str [ "one" "two" "three" ])
  • 6. Clojure Macros Macros use the source code as data (input) like functions use data "thread-first" macro (-> "first" (str " last")) (str "first" " last") "thread-last" macro (->> " last" (str " first")) Thread macro takes an expression to a form f(source code) -> source code ‘->’ : “term” ===> Form ‘-->’ : “term” ===> Form inserts the first term as the first /last item in second form inserts the first form as the first /last item in second form
  • 7. Clojure Memory Model Clojure is a dialect of Lisp that runs on the JVM. (Common Language Runtime (like JVM) and Javascript engines) Objectives What is a memory model why is it needed JMM what is it how does it work STM what is it how does it work
  • 8. Clojure Process core-async Summary Clojure Concurrency Vars Immutable by default Mutable call dynamic (def ^:dynamic *my-str-type* "mutable variable") As a mutable variable have thread local scope (visibility) Atoms Are visible (synchronised) (def my-atom (atom 10)) de-reference @my-atom (reset! my-atom 12) functional (swap! my-atom update ) Use swap! in STM block STM Refs Agents Refs ACID Transcational Atoms Update with alter in synchronised block (dosync (translate-point )) Agents Refs that update asynchronously (def my-agent (agent 10)) No strict consistency for reads (send my-agent update-my-agent)
  • 9. Clojure Web Applications Ring is a Clojure web applications library inspired by Python's WSGI and Ruby's Rack Compojure is a rest api for rapid development of web applications in Clojure https://github.com/weavejester/compojure In compojure, each route is an HTTP method paired with a URL-matching pattern Compojure route definitions are just functions configured for Ring (accept request maps and return response maps) 1. Use a template lein new compojure eddy_comp 2. run the Ring web server lein ring server 3. defroutes site-defaults src/eddy_compjure/handler.clj 4. :keys :plugins :ring project.clj 5. Access the context root localhost:3000 6. JSON https://github.com/dakrone/cheshire 7. ClojureScript configuration 8. ClojureScript rest client
  • 10. Functional Composition Arity arity 2 (def make-a-set (fn ([x] #{x}) ([x y] #{x y}))) (make-a-set 1) (make-a-set 1 2) Variadic functions (defn var-args [x & rest] (apply str (butlast rest) ) ) (var-args 0 1 2 3 4) Currying Currying is a way to generate a new function with an argument partially applied partial is a way of currying partial https://clojuredocs.org/clojure.core/partial (def make-a-set (fn ([x y] #{x y}))) ( (partial make-a-set 2) 3 ) What if we want to create a function not just a form (def make-a-set-5 (partial make-a-set 5)) (make-a-set-5 10)
  • 11. Clojure Concurrent tools: Atoms, Refs, Vars Objectives 1. What is a memory model why is it needed 2. JMM what is it how does it work 3. STM what is it how does it work Result 1. memory model is a set of rules implemented in hardware and software that controls the way variables are updated during program execution by multiple threads of execution 2. Java memory model (JMM) is a set of low level concurrency artifacts (locks, atomic variables and synchronisation(visibility) ) combined with high level frameworks (Executor Service, Futures, ForkJoin, …...) to implement a memory model. 3. Software Transactional Memory (STM) an ACID transactional system for how a variable that is shared between threads updates, STM is implemented with the low
  • 12. Functional recipe: Pure functions with Immutable Data Structures Pure Functions Side effects = changes that functions make in addition to their return value Pure functions do not depend on external data sources and do not provoke side effects of any kind. When invoked with a set of arguments, will always respond with the same return value Higher-Order Functions ● Takes one or more functions as arguments ● Returns a function as a result Clojure has families of higher order functions <==> Clojure Abstractions Eg sequence functions map reduce filter sequence <==> Data Structure Abstraction {sequence}
  • 13. Gradle Environment 1 install gradle .bashrc export GRADLE_HOME=/home/ubu/gradle export PATH=$PATH:$GRADLE_HOME/bin export JAVA_HOME=/usr/lib/jvm/java-8-oracle .bashrc export JAVA_HOME=/usr/lib/jvm/java-8-oracle export GRADLE_HOME=/home/ubu/gradle export PATH=$PATH:$GRADLE_HOME/bin source .bashrc
  • 14. Leiningen Environment Software Engineering Build Tools Compiling computer source code into binary code Packaging binary code Running tests Deployment to production systems Creating documentation and/or release notes Objectives 1. Install leningen 2. Understand Leiningen project layout 3. Understand Leiningen build script (dependencies ect ..) 4. Run the clojure repl
  • 15. Functional Recursive Data Flow Recursion is one of the fundamental techniques used in functional programming. Review Function literal ((fn [x y] #{x y}) 1 2) Function arity 2 (def make-a-set (fn ([x] #{x}) ([x y] #{x y}))) (make-a-set 1) (make-a-set 1 2) def special form is a way to assign a symbolic name to a piece of Clojure data