SlideShare une entreprise Scribd logo
1  sur  32
Programming with Freedom & Joy
Confessions of an ExJavaEE enthusiast that
found enlightenment through Clojure
Hildeberto Mendonça
@htmfilho
100 Years Anniversary of
General Relativity Theory
E = mc2
Philosophy Behind Relativity
Object Oriented and Imperative
●
Object oriented
– Created for simulation systems (Simula 67)
– Object represent state and behavior which is a requirement for simulations
– Very good for user interface development (a simulation of concrete objects. Ex. button)
– But, is it good for everything else?
– By putting in a distributed environment you have clones and reports of gang rapes
● Imperative
– The art of programming in sequential steps to accomplish tasks
– Sometimes the list of steps is so large that frameworks should be used to make the
work practical
– By mixing it with object-oriented programming you have nitroglycerin (steps to manage
states)
Java to Clojure
Public class StringUtils {
Public static boolean isBlank(String str) {
Int strlen;
if(str == null || (strlen = str.length()) == 0) {
Return true;
}
For (int i = 0; I < strlen; i++ ) {
if((Character.isWhitespace(str.charAt(i)) == false)) {
Return false;
}
}
Return true;
}
}
(defn blank? [s] (every? #(Character/isWhitespace %) s))
HDD (Handicraft Driven Development)
Java doesn't leave time for the
essential in live
What Happened Hildeberto?!
1.Oracle stopped supporting Glassfish
2.Pushed to look for alternatives
3.Started migrating to Jboss (Nightmare!!!)
4.Realized that Java EE is a broken standard
5.Pushed to look for alternatives once again
6.Found Scala + Akka + Play (Wonderfull!!!)
7.But Scala is pretty damn complex :-(
THE WORLD IS
SOOO COMPLEX!!!
I've met Clojure at Devoxx 2013
DJs mixing with it!! :o
The Turning Point Towards Clojure
Clojure
● Dialect of LISP (List Processing)
● Dynamically typed but strongly typed
● Functional (not purely functional, a bit more)
● Host interoperability
● Software transactional memory
● Everything is an expression
● Compiled
● Macros
● Lazy sequences
By Rich Hickey
LISP?
● Created by John McCarthy
● He coined the term “Artificial Intelligence”
● Exceptionally intelligent
● Created the “if” structure.
John McCarthy
Learn Once Code Everywhere
Java Clojure Bytecode JVM
C# Clojure CIL code CLR
Clojure ClojureScript JavaScript JS Engine
Python Clojure Python Cpython
● Hosted language
http://clojure.org
http://clojure.org/clojureclr
http://clojure.org/clojurescript
https://github.com/halgari/clojure-py
Syntax in One Slide
● Numbers – 3454.23
● Ratios – 3/56
● Strings - “Carnaval”
● Characters - a b return
● Symbols – alex b c
● Keywords - :a :b :c
● Booleans – true false
● Null – nil
● Regex patterns #”a*b”
● Lists (1 2 3 4 5 4)
● Vectors [1 2 3 3 5]
● Maps {:a 1 :b 2 :c 2}
● Sets #{1 2 3 4 5}
● Prefixes ' #() @ ~ ~@
● Macros
● ; (documentation)
It is simple because it is all about
interpretation of data structures, not text
REPL
Basic Side-by-Side with Java
Clojure
(not k)
(inc a)
(/ (+ x y) 2)
(instance? Java.utils.List al)
(if (not a) (inc b) (dec b))
(Math/pow 2 10)
(.someMethod obj “foo”
(.otherMethod otherObj o))
Java
!k
a++, ++a, a += 1, a + 1
(x + y) / 2
al instanceof java.util.List
!a ? b + 1 : b – 1;
Math.pow(2, 10);
obj.someMethod(“foo”,
otherObj.otherMethod(o));
Homoiconicity
● Code as data
(if (odd? 2) “odd” “even”)
● Significant simplification (less memorization)
(Symbol arg1 arg2 … argN)
You already learned 80% of what it takes to program in
Clojure!
● Metaprogramming facilities (macros)
(def n (fn […] …)) => (defn n […] ...)
● Represents the abstract syntax tree directly
Abstract Syntax Tree Example
● RequiresRole && userHasRole(“MODIFY”, assetId)
AND
requiresRole Call
userHasHole assetId
“MODIFY”
● (and requiresRole (userHasRole “MODIFY” assetId))
Data Structures
● Persistent (versioned)
● Immutable
T1 T2
Structural Sharing
(conj [1 2 3 4] 5)[1 2 3 4]
Traditional Evaluation
Code
Text
Compiler
Executable
.class/.jar
Run java JVM
Effect
Not happy with the result? Start over.
Characters
Bytecode
Clojure Evaluation
Code
file
Reader
Evaluator /
compiler
JVM
Effect
Not happy with the result? Send more code to the reader.
Characters
Data structures
Bytecode
Once started,
it keeps running
while you work.
Local / Remote
TCP/IP
Connection
Program
Characters
Data
structures
Macro
Data
structures
Macros
Data StructuresCode Data
You Macro
Tool Support
Cursive (IntelliJ)
Counterclockwise (Eclipse)
Visual Studio
LightTable
Emacs
Vim
LightTable
Written in ClojureScript
Community
● Everything is on GitHub:
https://github.com/clojure
● 70 user groups; only one in Brazil (São Paulo)
● Mailing list with ~10k users (everybody is nice)
● Position on Tiobe: 62
http://www.clojure-toolbox.com
http://www.braveclojure.com
http://www.4clojure.com
Books
Thanks!!
Hildeberto.com
@htmfilho

Contenu connexe

Tendances

Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Live coding scala 'the java of the future'
Live coding scala 'the java of the future'Live coding scala 'the java of the future'
Live coding scala 'the java of the future'
Xebia Nederland BV
 
Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python Programmers
Vsevolod Dyomkin
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 

Tendances (20)

Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Python Memory Management 101(Europython)
Python Memory Management 101(Europython)Python Memory Management 101(Europython)
Python Memory Management 101(Europython)
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Clojure Small Intro
Clojure Small IntroClojure Small Intro
Clojure Small Intro
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)
 
Lua Study Share
Lua Study ShareLua Study Share
Lua Study Share
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time Checks
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
Live coding scala 'the java of the future'
Live coding scala 'the java of the future'Live coding scala 'the java of the future'
Live coding scala 'the java of the future'
 
Kotlin : Happy Development
Kotlin : Happy DevelopmentKotlin : Happy Development
Kotlin : Happy Development
 
Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python Programmers
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Redis: Lua scripts - a primer and use cases
Redis: Lua scripts - a primer and use casesRedis: Lua scripts - a primer and use cases
Redis: Lua scripts - a primer and use cases
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 
3 little clojure functions ii
3 little clojure functions ii3 little clojure functions ii
3 little clojure functions ii
 

En vedette

Local Palate Ark of Taste Article 9.15
Local Palate Ark of Taste Article 9.15Local Palate Ark of Taste Article 9.15
Local Palate Ark of Taste Article 9.15
John Haddad
 
Peering 101 and the peering simulation game
Peering 101 and the peering simulation gamePeering 101 and the peering simulation game
Peering 101 and the peering simulation game
Internet Society
 
Happy Energy - The connection between positive thinking and sustainable living
Happy Energy - The connection between positive thinking and sustainable livingHappy Energy - The connection between positive thinking and sustainable living
Happy Energy - The connection between positive thinking and sustainable living
erik_schoppen
 
Logをs3とredshiftに格納する仕組み
Logをs3とredshiftに格納する仕組みLogをs3とredshiftに格納する仕組み
Logをs3とredshiftに格納する仕組み
Ken Morishita
 

En vedette (20)

97 Things Every Programmer Should Know
97 Things Every Programmer Should Know97 Things Every Programmer Should Know
97 Things Every Programmer Should Know
 
Yokogawa & NextNine – Lessons Learned: Global Cybersecurity Management System...
Yokogawa & NextNine – Lessons Learned: Global Cybersecurity Management System...Yokogawa & NextNine – Lessons Learned: Global Cybersecurity Management System...
Yokogawa & NextNine – Lessons Learned: Global Cybersecurity Management System...
 
Local Palate Ark of Taste Article 9.15
Local Palate Ark of Taste Article 9.15Local Palate Ark of Taste Article 9.15
Local Palate Ark of Taste Article 9.15
 
RDS for MySQL, No BS Operations and Patterns
RDS for MySQL, No BS Operations and PatternsRDS for MySQL, No BS Operations and Patterns
RDS for MySQL, No BS Operations and Patterns
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js
 
Highbank Arranges Shares for Debt for $565,343 Convertible Debenture Interest...
Highbank Arranges Shares for Debt for $565,343 Convertible Debenture Interest...Highbank Arranges Shares for Debt for $565,343 Convertible Debenture Interest...
Highbank Arranges Shares for Debt for $565,343 Convertible Debenture Interest...
 
Swedish IT Outsourcing Intelligence Report 2012
Swedish IT Outsourcing Intelligence Report 2012Swedish IT Outsourcing Intelligence Report 2012
Swedish IT Outsourcing Intelligence Report 2012
 
SEC MBE PCB
SEC MBE PCB SEC MBE PCB
SEC MBE PCB
 
Apache Kafka Reliability Guarantees StrataHadoop NYC 2015
Apache Kafka Reliability Guarantees StrataHadoop NYC 2015 Apache Kafka Reliability Guarantees StrataHadoop NYC 2015
Apache Kafka Reliability Guarantees StrataHadoop NYC 2015
 
Peering 101 and the peering simulation game
Peering 101 and the peering simulation gamePeering 101 and the peering simulation game
Peering 101 and the peering simulation game
 
Tool of the month: Der Kneipenblock
Tool of the month: Der KneipenblockTool of the month: Der Kneipenblock
Tool of the month: Der Kneipenblock
 
Digital Textile Printing
Digital Textile Printing Digital Textile Printing
Digital Textile Printing
 
Happy Energy - The connection between positive thinking and sustainable living
Happy Energy - The connection between positive thinking and sustainable livingHappy Energy - The connection between positive thinking and sustainable living
Happy Energy - The connection between positive thinking and sustainable living
 
Social Recruiting, Talent Acquistion and Recruitment in 2015
Social Recruiting, Talent Acquistion and Recruitment in 2015Social Recruiting, Talent Acquistion and Recruitment in 2015
Social Recruiting, Talent Acquistion and Recruitment in 2015
 
Blue light presentation
Blue light presentationBlue light presentation
Blue light presentation
 
Managen von ovm server sparc mit dem vm manager, o ps center oder vdcf-roman ...
Managen von ovm server sparc mit dem vm manager, o ps center oder vdcf-roman ...Managen von ovm server sparc mit dem vm manager, o ps center oder vdcf-roman ...
Managen von ovm server sparc mit dem vm manager, o ps center oder vdcf-roman ...
 
Avoid the Oracle SE2 Trap with EnterpriseDB & Palisade Compliance
Avoid the Oracle SE2 Trap with EnterpriseDB & Palisade ComplianceAvoid the Oracle SE2 Trap with EnterpriseDB & Palisade Compliance
Avoid the Oracle SE2 Trap with EnterpriseDB & Palisade Compliance
 
MHAを検証して導入した話
MHAを検証して導入した話MHAを検証して導入した話
MHAを検証して導入した話
 
Create a Hollywood Style Employer Brand
Create a Hollywood Style Employer BrandCreate a Hollywood Style Employer Brand
Create a Hollywood Style Employer Brand
 
Logをs3とredshiftに格納する仕組み
Logをs3とredshiftに格納する仕組みLogをs3とredshiftに格納する仕組み
Logをs3とredshiftに格納する仕組み
 

Similaire à Programming with Freedom & Joy

Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
elliando dias
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
Trends in programming languages
Trends in programming languagesTrends in programming languages
Trends in programming languages
Antya Dev
 

Similaire à Programming with Freedom & Joy (20)

Clojure
ClojureClojure
Clojure
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming Languages
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REA
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Scala clojure techday_2011
Scala clojure techday_2011Scala clojure techday_2011
Scala clojure techday_2011
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
 
Trends in programming languages
Trends in programming languagesTrends in programming languages
Trends in programming languages
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Java
JavaJava
Java
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 

Dernier

Dernier (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Programming with Freedom & Joy

  • 1. Programming with Freedom & Joy Confessions of an ExJavaEE enthusiast that found enlightenment through Clojure Hildeberto Mendonça @htmfilho
  • 2. 100 Years Anniversary of General Relativity Theory E = mc2
  • 4. Object Oriented and Imperative ● Object oriented – Created for simulation systems (Simula 67) – Object represent state and behavior which is a requirement for simulations – Very good for user interface development (a simulation of concrete objects. Ex. button) – But, is it good for everything else? – By putting in a distributed environment you have clones and reports of gang rapes ● Imperative – The art of programming in sequential steps to accomplish tasks – Sometimes the list of steps is so large that frameworks should be used to make the work practical – By mixing it with object-oriented programming you have nitroglycerin (steps to manage states)
  • 5.
  • 6. Java to Clojure Public class StringUtils { Public static boolean isBlank(String str) { Int strlen; if(str == null || (strlen = str.length()) == 0) { Return true; } For (int i = 0; I < strlen; i++ ) { if((Character.isWhitespace(str.charAt(i)) == false)) { Return false; } } Return true; } } (defn blank? [s] (every? #(Character/isWhitespace %) s))
  • 7. HDD (Handicraft Driven Development)
  • 8. Java doesn't leave time for the essential in live
  • 9. What Happened Hildeberto?! 1.Oracle stopped supporting Glassfish 2.Pushed to look for alternatives 3.Started migrating to Jboss (Nightmare!!!) 4.Realized that Java EE is a broken standard 5.Pushed to look for alternatives once again 6.Found Scala + Akka + Play (Wonderfull!!!) 7.But Scala is pretty damn complex :-(
  • 10. THE WORLD IS SOOO COMPLEX!!!
  • 11. I've met Clojure at Devoxx 2013 DJs mixing with it!! :o
  • 12. The Turning Point Towards Clojure
  • 13. Clojure ● Dialect of LISP (List Processing) ● Dynamically typed but strongly typed ● Functional (not purely functional, a bit more) ● Host interoperability ● Software transactional memory ● Everything is an expression ● Compiled ● Macros ● Lazy sequences By Rich Hickey
  • 14. LISP? ● Created by John McCarthy ● He coined the term “Artificial Intelligence” ● Exceptionally intelligent ● Created the “if” structure. John McCarthy
  • 15. Learn Once Code Everywhere Java Clojure Bytecode JVM C# Clojure CIL code CLR Clojure ClojureScript JavaScript JS Engine Python Clojure Python Cpython ● Hosted language http://clojure.org http://clojure.org/clojureclr http://clojure.org/clojurescript https://github.com/halgari/clojure-py
  • 16. Syntax in One Slide ● Numbers – 3454.23 ● Ratios – 3/56 ● Strings - “Carnaval” ● Characters - a b return ● Symbols – alex b c ● Keywords - :a :b :c ● Booleans – true false ● Null – nil ● Regex patterns #”a*b” ● Lists (1 2 3 4 5 4) ● Vectors [1 2 3 3 5] ● Maps {:a 1 :b 2 :c 2} ● Sets #{1 2 3 4 5} ● Prefixes ' #() @ ~ ~@ ● Macros ● ; (documentation) It is simple because it is all about interpretation of data structures, not text
  • 17. REPL
  • 18. Basic Side-by-Side with Java Clojure (not k) (inc a) (/ (+ x y) 2) (instance? Java.utils.List al) (if (not a) (inc b) (dec b)) (Math/pow 2 10) (.someMethod obj “foo” (.otherMethod otherObj o)) Java !k a++, ++a, a += 1, a + 1 (x + y) / 2 al instanceof java.util.List !a ? b + 1 : b – 1; Math.pow(2, 10); obj.someMethod(“foo”, otherObj.otherMethod(o));
  • 19. Homoiconicity ● Code as data (if (odd? 2) “odd” “even”) ● Significant simplification (less memorization) (Symbol arg1 arg2 … argN) You already learned 80% of what it takes to program in Clojure! ● Metaprogramming facilities (macros) (def n (fn […] …)) => (defn n […] ...) ● Represents the abstract syntax tree directly
  • 20. Abstract Syntax Tree Example ● RequiresRole && userHasRole(“MODIFY”, assetId) AND requiresRole Call userHasHole assetId “MODIFY” ● (and requiresRole (userHasRole “MODIFY” assetId))
  • 21. Data Structures ● Persistent (versioned) ● Immutable T1 T2 Structural Sharing (conj [1 2 3 4] 5)[1 2 3 4]
  • 22. Traditional Evaluation Code Text Compiler Executable .class/.jar Run java JVM Effect Not happy with the result? Start over. Characters Bytecode
  • 23. Clojure Evaluation Code file Reader Evaluator / compiler JVM Effect Not happy with the result? Send more code to the reader. Characters Data structures Bytecode Once started, it keeps running while you work. Local / Remote TCP/IP Connection Program Characters Data structures Macro Data structures
  • 25. Tool Support Cursive (IntelliJ) Counterclockwise (Eclipse) Visual Studio LightTable Emacs Vim
  • 27. Community ● Everything is on GitHub: https://github.com/clojure ● 70 user groups; only one in Brazil (São Paulo) ● Mailing list with ~10k users (everybody is nice) ● Position on Tiobe: 62
  • 31. Books