SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
The Clojure
Programming
Language
CS571ProgrammingLanguages
Brian Gracin
Jenny Pawlak
Jacquelyn S Victoria
90 Second Overview…..
Clojure is…..
- A dialect of Lisp
- General purpose language
- Emphasizes functional programming
- Runs on the Java Virtual Machine
- Designed for Concurrency
- Used in industry -- CapitalOne, Amazon, Facebook, Oracle
https://gooroo.io/GoorooTHINK/Article/16300/Programming-languages--salaries-and-demand-May-2015
Background
Simplicity
“We suffer from so much incidental complexity in traditional OO languages, both
syntactic and semantic, that I don’t think we even realise it anymore. I wanted to
make ‘doing the right thing’ not a matter of convention and discipline, but the
default. I wanted a solid concurrency story and great interoperability with existing
Java libraries,.” -Rich Hickey, creator of Clojure
Rich Hickey, Clojure, Benevolent Dictator for Life
CLOJURE:
- First Available: 2007
- Latest Stable Release: 1.8 January 19, 2016
Clojure’s Influences
Why Lisp?
● Entire Language:
○ 7 functions
○ 2 labels
Why JVM?
● Familiar - run just like Java apps
● Use some familiar Java objects
● Many available libraries
● Established track record
● Now open-sourced.
http://www.braveclojure.com/java/ (Chapter 12)
clojure.org/about/rationale
What are Clojure’s Characteristics?
● Functional - succinct, understandable, reusable
● Defaults to Immutability
○ Simplifies reasoning and testing
○ Easier to share objects
○ Thread safe
● but allows mutability!
● Code-as-Data (Homoiconicity)
● Syntactic Abstraction
Immutable objects are always thread safe.
—Brian Goetz, Java Concurrency in Practice
The Joy of Clojure Chapter 6.
Examples
Homoiconicity
Code written in the language is encoded as
data structures that the language has tools to
manipulate
Syntatic Abstraction
Permits the definition of new language
constructs whose meaning can be understood
in terms of static translation into the core
language.As Data:
As Code.
LISP
Java
functional
Java’s
Librariesiteration
interfaces
Immutable
datatypes
Lazy
evaluation
Clojure
Core
Truthiness
What is truthy?
● true
● 1
● (= 1 1)
● 0
● “False”
● []
● Literally any value but false or nil
What is falsey?
● false
● nil
● (= 3 1)
Nil Punning: Handling Clojure’s
empty sequences that are Truthy
Every[thing] is "true" all the time, unless it is nil or false.
—Brian Goetz,
The Joy of Clojure
Clojure Data Structures
● They are immutable by default
● Support metadata
● Implement java.lang.Iterable
● Implement the read-only part of java.util.Collection
http://clojure.org/reference/data_structures
Data Collection Types - Part 1
Lists
Singly linked lists
First item in calling position
Heterogeneous elements
Compare to Haskell:
Homogeneous lists
Vectors
Simply evaluate each item in order.
Quick look-up times
Heterogeneous elements
No calling position
Data Collection Types - Part 2
Maps
Maps store unique keys and one value per
key (dictionaries and hashes)
Two types:
1. Hashed: key has hashCode, equals
2. Sorted: implement Comparable
Sets
Store zero or more unique items
Some Mutable Data Structures!
Atoms
Managed shared synchronous independent
state
Refs
Transaction references
Safe shared use of mutable storage
Require SW transactional memory system
Agents
Independent, asynchronous change of
individual locations
Only allow change due to an action
Var
Mutable storage location
Can be dynamically rebound per thread
Ensure safety through thread isolation
MUTABLE DATA Type Comparison
Functions
First Class
Created on demand
Stored in a data structure
Passed as an argument
Returned as a value
Higher-Order
Takes one or more function args
Returns function as result
Pure Functions
ALWAYS return same result
No observable side effects
(defn
[arg1 arg2]
(;function code
))
def or defn?
● Both bind a symbol or name
● def is only evaluated once
● defn is evaluated every time it is called
Examples
Quick Comparison
Haskell:
average numbers = (fold (+) (numbers) ) / (length(numbers))
Clojure:
(defn average [numbers] (/ (reduce + numbers) (count numbers)))
Quick Comparison
Haskell:
fact x = if x == 0 then 1 else x * fact(x-1)
Clojure:
(defn factorial [n] (if (= n 0) 1 (* n (factorial (dec n)))))
Code example
https://rosettacode.org/wiki/Palindrome_detection#Clojure
Intermediate
Higher-Order Functions
Map
>(map * [1 2 3 4] [5 6 7 8])
(5 12 21 32)
Reduce
>(reduce max [0 -3 10 48])
48
Comp
((comp str - +) 4 5) is equivalent to
(str ( - ( + 4 5)))
Partial
(defn add10 (partial + 10))
>(add10 3)
13
>(add10 3 4 8)
25
Anonymous Functions
Fn
>(map (fn [x] (* x x)) (range 1 10))
(1 4 9 16 25 36 49 64 81)
Macros
(defmacro infix
[infixed]
(list (second infixed)
(first infixed)
(last infixed)))
>(1 + 2)
error
>(infix (1 + 2))
3
Java Interop
Accessing member functions
>(.toUpperCase "fred")
"FRED"
>(Math/pow 2 4)
16
( proxy [class-and-interfaces] [args]
fs+)
Concurrency
Doseq
Do over a sequence
Dosync
Do all or nothing
Future
Generate a thread
Delay
Bind function but don’t evaluate
Promise
Create a binding with no value
Uses
Clojure Shortcomings:
● Dynamic type checking
● Doesn’t scale well: code size, team size, time elapsed
● Startup time
● If JVM is not a good solution, then Clojure isn’t either
○ Systems programming limitations
○ Real-Time
http://martintrojer.github.io/beyond-clojure/2016/04/19/beyond-clojure-prelude
https://www.quora.com/What-is-clojure-bad-at
Clojure in Industry
Clojure in Industry
The Boeing 737 MAX Onboard Maintenance Function is 32,000 lines of Clojure.
First time Clojure used in aircraft software.
One of the largest code bases to date.
When to choose Clojure?
Handle large amounts of data with significant hardware limitations.
When you want more concise code, easier to test and debug.
Easier to get over 90% coverage with unit testing.
When JVM or CLR can be used.
Clojure developers are the
happiest developers
From an analysis of Reddit comments,
http://www.itworld.com/article/2693998/big-data/clojure-
developers-are-the-happiest-developers.html
Online Resources/Tutorials
Clojure.org
Clojuredocs.org
Clojure-doc.org
Clojure-by-example
ClojureTV (Youtube channel)
Clojure for the Brave and True
Further Info
The Joy of Clojure
Book by Chris Houser and Michael Fogus
Clojure Programming
Book by By Chas Emerick, Brian Carper, Christophe Grand
Simple Made Easy
Video by Rich Hickey

Weitere ähnliche Inhalte

Was ist angesagt?

Strings in Java
Strings in Java Strings in Java
Strings in Java Hitesh-Java
 
Gentle Introduction to Scala
Gentle Introduction to ScalaGentle Introduction to Scala
Gentle Introduction to ScalaFangda Wang
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programmingAssaf Gannon
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQLvaluebound
 
Functional and Event Driven - another approach to domain modeling
Functional and Event Driven - another approach to domain modelingFunctional and Event Driven - another approach to domain modeling
Functional and Event Driven - another approach to domain modelingDebasish Ghosh
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Modulearjun singh
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions Reem Alattas
 
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataModel serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataGetInData
 
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdf
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdfServerless Machine Learning Model Inference on Kubernetes with KServe.pdf
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdfStavros Kontopoulos
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHPShweta A
 

Was ist angesagt? (20)

Strings in Java
Strings in Java Strings in Java
Strings in Java
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Quiery builder
Quiery builderQuiery builder
Quiery builder
 
Gentle Introduction to Scala
Gentle Introduction to ScalaGentle Introduction to Scala
Gentle Introduction to Scala
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
Python decorators
Python decoratorsPython decorators
Python decorators
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQL
 
Functional and Event Driven - another approach to domain modeling
Functional and Event Driven - another approach to domain modelingFunctional and Event Driven - another approach to domain modeling
Functional and Event Driven - another approach to domain modeling
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Module
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataModel serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
 
Monitoring Solutions for APIs
Monitoring Solutions for APIsMonitoring Solutions for APIs
Monitoring Solutions for APIs
 
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdf
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdfServerless Machine Learning Model Inference on Kubernetes with KServe.pdf
Serverless Machine Learning Model Inference on Kubernetes with KServe.pdf
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 

Ähnlich wie Introductory Clojure Presentation

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
Functional (web) development with Clojure
Functional (web) development with ClojureFunctional (web) development with Clojure
Functional (web) development with ClojureHenrik Eneroth
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypseelliando dias
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of ClojureDavid Leung
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
 
Javascript Performance
Javascript PerformanceJavascript Performance
Javascript Performanceolivvv
 
Indic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndicThreads
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularityelliando dias
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureJayaram Sankaranarayanan
 
Exploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesExploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesTobias Lindaaker
 

Ähnlich wie Introductory Clojure Presentation (20)

Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
Functional (web) development with Clojure
Functional (web) development with ClojureFunctional (web) development with Clojure
Functional (web) development with Clojure
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Clojure
ClojureClojure
Clojure
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Javascript Performance
Javascript PerformanceJavascript Performance
Javascript Performance
 
Indic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvm
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularity
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
Exploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesExploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic Languages
 
All of javascript
All of javascriptAll of javascript
All of javascript
 

Kürzlich hochgeladen

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 

Introductory Clojure Presentation

  • 2. 90 Second Overview….. Clojure is….. - A dialect of Lisp - General purpose language - Emphasizes functional programming - Runs on the Java Virtual Machine - Designed for Concurrency - Used in industry -- CapitalOne, Amazon, Facebook, Oracle
  • 5. Simplicity “We suffer from so much incidental complexity in traditional OO languages, both syntactic and semantic, that I don’t think we even realise it anymore. I wanted to make ‘doing the right thing’ not a matter of convention and discipline, but the default. I wanted a solid concurrency story and great interoperability with existing Java libraries,.” -Rich Hickey, creator of Clojure Rich Hickey, Clojure, Benevolent Dictator for Life CLOJURE: - First Available: 2007 - Latest Stable Release: 1.8 January 19, 2016
  • 7. Why Lisp? ● Entire Language: ○ 7 functions ○ 2 labels
  • 8. Why JVM? ● Familiar - run just like Java apps ● Use some familiar Java objects ● Many available libraries ● Established track record ● Now open-sourced. http://www.braveclojure.com/java/ (Chapter 12) clojure.org/about/rationale
  • 9. What are Clojure’s Characteristics? ● Functional - succinct, understandable, reusable ● Defaults to Immutability ○ Simplifies reasoning and testing ○ Easier to share objects ○ Thread safe ● but allows mutability! ● Code-as-Data (Homoiconicity) ● Syntactic Abstraction Immutable objects are always thread safe. —Brian Goetz, Java Concurrency in Practice The Joy of Clojure Chapter 6.
  • 10. Examples Homoiconicity Code written in the language is encoded as data structures that the language has tools to manipulate Syntatic Abstraction Permits the definition of new language constructs whose meaning can be understood in terms of static translation into the core language.As Data: As Code.
  • 12. Core
  • 13. Truthiness What is truthy? ● true ● 1 ● (= 1 1) ● 0 ● “False” ● [] ● Literally any value but false or nil What is falsey? ● false ● nil ● (= 3 1) Nil Punning: Handling Clojure’s empty sequences that are Truthy Every[thing] is "true" all the time, unless it is nil or false. —Brian Goetz, The Joy of Clojure
  • 14. Clojure Data Structures ● They are immutable by default ● Support metadata ● Implement java.lang.Iterable ● Implement the read-only part of java.util.Collection http://clojure.org/reference/data_structures
  • 15. Data Collection Types - Part 1 Lists Singly linked lists First item in calling position Heterogeneous elements Compare to Haskell: Homogeneous lists Vectors Simply evaluate each item in order. Quick look-up times Heterogeneous elements No calling position
  • 16. Data Collection Types - Part 2 Maps Maps store unique keys and one value per key (dictionaries and hashes) Two types: 1. Hashed: key has hashCode, equals 2. Sorted: implement Comparable Sets Store zero or more unique items
  • 17. Some Mutable Data Structures! Atoms Managed shared synchronous independent state Refs Transaction references Safe shared use of mutable storage Require SW transactional memory system Agents Independent, asynchronous change of individual locations Only allow change due to an action Var Mutable storage location Can be dynamically rebound per thread Ensure safety through thread isolation
  • 18. MUTABLE DATA Type Comparison
  • 19. Functions First Class Created on demand Stored in a data structure Passed as an argument Returned as a value Higher-Order Takes one or more function args Returns function as result Pure Functions ALWAYS return same result No observable side effects (defn [arg1 arg2] (;function code )) def or defn? ● Both bind a symbol or name ● def is only evaluated once ● defn is evaluated every time it is called
  • 21. Quick Comparison Haskell: average numbers = (fold (+) (numbers) ) / (length(numbers)) Clojure: (defn average [numbers] (/ (reduce + numbers) (count numbers)))
  • 22. Quick Comparison Haskell: fact x = if x == 0 then 1 else x * fact(x-1) Clojure: (defn factorial [n] (if (= n 0) 1 (* n (factorial (dec n)))))
  • 25. Higher-Order Functions Map >(map * [1 2 3 4] [5 6 7 8]) (5 12 21 32) Reduce >(reduce max [0 -3 10 48]) 48 Comp ((comp str - +) 4 5) is equivalent to (str ( - ( + 4 5))) Partial (defn add10 (partial + 10)) >(add10 3) 13 >(add10 3 4 8) 25
  • 26. Anonymous Functions Fn >(map (fn [x] (* x x)) (range 1 10)) (1 4 9 16 25 36 49 64 81)
  • 27. Macros (defmacro infix [infixed] (list (second infixed) (first infixed) (last infixed))) >(1 + 2) error >(infix (1 + 2)) 3
  • 28. Java Interop Accessing member functions >(.toUpperCase "fred") "FRED" >(Math/pow 2 4) 16 ( proxy [class-and-interfaces] [args] fs+)
  • 29. Concurrency Doseq Do over a sequence Dosync Do all or nothing Future Generate a thread Delay Bind function but don’t evaluate Promise Create a binding with no value
  • 30. Uses
  • 31. Clojure Shortcomings: ● Dynamic type checking ● Doesn’t scale well: code size, team size, time elapsed ● Startup time ● If JVM is not a good solution, then Clojure isn’t either ○ Systems programming limitations ○ Real-Time http://martintrojer.github.io/beyond-clojure/2016/04/19/beyond-clojure-prelude https://www.quora.com/What-is-clojure-bad-at
  • 33. Clojure in Industry The Boeing 737 MAX Onboard Maintenance Function is 32,000 lines of Clojure. First time Clojure used in aircraft software. One of the largest code bases to date.
  • 34. When to choose Clojure? Handle large amounts of data with significant hardware limitations. When you want more concise code, easier to test and debug. Easier to get over 90% coverage with unit testing. When JVM or CLR can be used.
  • 35. Clojure developers are the happiest developers From an analysis of Reddit comments, http://www.itworld.com/article/2693998/big-data/clojure- developers-are-the-happiest-developers.html
  • 37. Further Info The Joy of Clojure Book by Chris Houser and Michael Fogus Clojure Programming Book by By Chas Emerick, Brian Carper, Christophe Grand Simple Made Easy Video by Rich Hickey