SlideShare a Scribd company logo
Clojure for Rubyists

   For Montreal.rb on September 21st 2010
                 By Jeff Heon
Clojure in a nutshell



   ●Functional
   ●Concurrency

   ●JVM

   ●Lisp
Similarities

       Interactive development


Ruby      Clojure

irb       REPL (read eval loop print)
          java -cp clojure.jar clojure.main
Similarities

Ruby symbols are Clojure keywords.



Ruby             Clojure

:symbol          :keyword
Similarities

           In a conditional, nil and false evalute
           to false and everything else to true.

Ruby                              Clojure

if 0 then true end                (if 0 true)
=> true                           => true

if nil then true else false end   (if nil true false)
=> false                          => false
Similarities

             Last expression in a method is the
                       return value.

Ruby                                  Clojure

def convert_farenheit_to_celcius(f)   (defn convert-farenheit-to-celcius [f]
  (f - 32) * 5.0 / 9                    (* (- f 32)
end                                        (/ 5.0 0)))
Basic types

Ruby                                Clojure
letter_digit = /^[a-zA-Z][0-9]$/    (def letter-digit #"^[a-zA-Z][0-9]$")

[0, 'Ruby', 42]                     [0 "Ruby" 42]

my_array[0]                         (my-vector 0)
{ :r => 'Ruby', :c => 'Clojure' }   { :r "Ruby" :c "Clojure" }

#Accessing                          ;Accessing
my_hash[:r]                         (my-hash :c)
Functional

Ruby                               Clojure


def odd?(n) (n % 2) == 1 end       (defn odd? [n] (= 1 (mod n 2)))

#Sum of odd numbers from 0 to 99   ;Sum of odd numbers from 0 to 99
(0..99).                           (reduce
select { |n| odd? n }.                +
inject(0) { |acc, n| acc + n }        (filter odd? (range 100)))

=> 2500                            => 2500
Functional, but lazy

Ruby                              Clojure


def odd_trace?(n)                 (defn odd-trace? [n]
  puts n                            (print n)
  (n % 2) == 1                      (= 1 (mod n 2)))
end

#Sum of odd numbers from 0 to 9   ;Sum of odd numbers from 0 to 9

(0..99).                          (reduce +
select { |n| odd_trace? n }.        (take 10
first(10).                            (filter odd-trace? (range 100))))
inject(0) { |acc, n| acc + n }

=> prints 0 to 99, returns 100    => prints 0 to 31, returns 100
Immutable data structure


Data structure are always immutable.
Adding or removing an element to an array,
vector, hash or set will always return a new
collection.

But, they are efficient because they are persistant
(in the sense that they share structure.)
Concurrency


Software transactional memory
Or having multiple threads access the same
reference using transactions instead of locks.

STMs are not all the same (like GC)
Readers are never blocked.
Works hand in hand with persistant data structure.
Ref

           1




@A    A    2




@A         3
Where did my books go?
(def book1
 { :author "David Flanagan" :title "The Ruby Programming language" })

(def book2
 { :author "Gregory Brown" :title "Ruby Best Practices"})

(def home-books (ref #{book1 book2}))

(def lent-books (ref #{}))

(alter home-books disj book1) => No transaction running

(dosync
    (alter home-books disj book1)
    (alter lent-books conj book1))

@home-books => #{{:author "Gregory Brown", :title "Ruby Best Practices"}}

@lent-books => #{{:author "David Flanagan", :title "The Ruby Programming
language"}}
Further exploration
If nothing else: Are we there yet?

Main site: Clojure.org

News & getting started: Disclojure

Books (a comparison)
●Programming Clojure

●Clojure in Action

●The Joy of Clojure

●Practical Clojure

●And one upcoming from O'Reilly

More Related Content

What's hot

Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animationLovelyn Rose
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional ProgrammingYiguang Hu
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General IntroductionThomas Johnston
 
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212Mahmoud Samir Fayed
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NETFuture Processing
 
Elm introduction
Elm   introductionElm   introduction
Elm introductionMix & Go
 
Ruby : Block, Proc and, lambda
Ruby : Block, Proc and, lambdaRuby : Block, Proc and, lambda
Ruby : Block, Proc and, lambdaMatthieuSegret
 
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScriptJosh Mock
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Platonov Sergey
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScriptJoseph Smith
 

What's hot (20)

Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Beginning Python
Beginning PythonBeginning Python
Beginning Python
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
 
Briefly Rust
Briefly RustBriefly Rust
Briefly Rust
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
Talk Code
Talk CodeTalk Code
Talk Code
 
Elm introduction
Elm   introductionElm   introduction
Elm introduction
 
Ruby : Block, Proc and, lambda
Ruby : Block, Proc and, lambdaRuby : Block, Proc and, lambda
Ruby : Block, Proc and, lambda
 
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScript
 
Cquestions
Cquestions Cquestions
Cquestions
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
 

Viewers also liked

Введение в Clojure (Margincon 2010)
Введение в Clojure (Margincon 2010)Введение в Clojure (Margincon 2010)
Введение в Clojure (Margincon 2010)Alex Ott
 
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)Howard Lewis Ship
 
Clojure: Lisp for the modern world (русская версия)
Clojure: Lisp for the modern world (русская версия)Clojure: Lisp for the modern world (русская версия)
Clojure: Lisp for the modern world (русская версия)Alex Ott
 
Clojure talk at Münster JUG
Clojure talk at Münster JUGClojure talk at Münster JUG
Clojure talk at Münster JUGAlex Ott
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Howard Lewis Ship
 
Onyx data processing the clojure way
Onyx   data processing  the clojure wayOnyx   data processing  the clojure way
Onyx data processing the clojure wayBahadir Cambel
 
A deep dive into Clojure's data structures - EuroClojure 2015
A deep dive into Clojure's data structures - EuroClojure 2015A deep dive into Clojure's data structures - EuroClojure 2015
A deep dive into Clojure's data structures - EuroClojure 2015Mohit Thatte
 
Practical Clojure Programming
Practical Clojure ProgrammingPractical Clojure Programming
Practical Clojure ProgrammingHoward Lewis Ship
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingHoward Lewis Ship
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentMaty Fedak
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data ScienceMike Anderson
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to ClojureRenzo Borgatti
 
Doing data science with Clojure
Doing data science with ClojureDoing data science with Clojure
Doing data science with ClojureSimon Belak
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojureAlex Miller
 

Viewers also liked (15)

Введение в Clojure (Margincon 2010)
Введение в Clojure (Margincon 2010)Введение в Clojure (Margincon 2010)
Введение в Clojure (Margincon 2010)
 
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
 
Clojure: Lisp for the modern world (русская версия)
Clojure: Lisp for the modern world (русская версия)Clojure: Lisp for the modern world (русская версия)
Clojure: Lisp for the modern world (русская версия)
 
Clojure talk at Münster JUG
Clojure talk at Münster JUGClojure talk at Münster JUG
Clojure talk at Münster JUG
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 
Onyx data processing the clojure way
Onyx   data processing  the clojure wayOnyx   data processing  the clojure way
Onyx data processing the clojure way
 
A deep dive into Clojure's data structures - EuroClojure 2015
A deep dive into Clojure's data structures - EuroClojure 2015A deep dive into Clojure's data structures - EuroClojure 2015
A deep dive into Clojure's data structures - EuroClojure 2015
 
Codemash-Clojure.pdf
Codemash-Clojure.pdfCodemash-Clojure.pdf
Codemash-Clojure.pdf
 
Practical Clojure Programming
Practical Clojure ProgrammingPractical Clojure Programming
Practical Clojure Programming
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of Programming
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Doing data science with Clojure
Doing data science with ClojureDoing data science with Clojure
Doing data science with Clojure
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojure
 

Similar to Clojure for Rubyists

Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyVysakh Sreenivasan
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to heroDiego Lemos
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartChen Fisher
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
Python decorators (中文)
Python decorators (中文)Python decorators (中文)
Python decorators (中文)Yiwei Chen
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 

Similar to Clojure for Rubyists (20)

Codeware
CodewareCodeware
Codeware
 
06 ruby variables
06 ruby variables06 ruby variables
06 ruby variables
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Scala e JRuby
Scala e JRubyScala e JRuby
Scala e JRuby
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Python decorators (中文)
Python decorators (中文)Python decorators (中文)
Python decorators (中文)
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Ruby.new @ VilniusRB
Ruby.new @ VilniusRBRuby.new @ VilniusRB
Ruby.new @ VilniusRB
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
ruby1_6up
ruby1_6upruby1_6up
ruby1_6up
 
ruby1_6up
ruby1_6upruby1_6up
ruby1_6up
 

Recently uploaded

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024TopCSSGallery
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKUXDXConf
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty SecureFemke de Vroome
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxEasyPrinterHelp
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 

Recently uploaded (20)

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 

Clojure for Rubyists

  • 1. Clojure for Rubyists For Montreal.rb on September 21st 2010 By Jeff Heon
  • 2. Clojure in a nutshell ●Functional ●Concurrency ●JVM ●Lisp
  • 3. Similarities Interactive development Ruby Clojure irb REPL (read eval loop print) java -cp clojure.jar clojure.main
  • 4. Similarities Ruby symbols are Clojure keywords. Ruby Clojure :symbol :keyword
  • 5. Similarities In a conditional, nil and false evalute to false and everything else to true. Ruby Clojure if 0 then true end (if 0 true) => true => true if nil then true else false end (if nil true false) => false => false
  • 6. Similarities Last expression in a method is the return value. Ruby Clojure def convert_farenheit_to_celcius(f) (defn convert-farenheit-to-celcius [f] (f - 32) * 5.0 / 9 (* (- f 32) end (/ 5.0 0)))
  • 7. Basic types Ruby Clojure letter_digit = /^[a-zA-Z][0-9]$/ (def letter-digit #"^[a-zA-Z][0-9]$") [0, 'Ruby', 42] [0 "Ruby" 42] my_array[0] (my-vector 0) { :r => 'Ruby', :c => 'Clojure' } { :r "Ruby" :c "Clojure" } #Accessing ;Accessing my_hash[:r] (my-hash :c)
  • 8. Functional Ruby Clojure def odd?(n) (n % 2) == 1 end (defn odd? [n] (= 1 (mod n 2))) #Sum of odd numbers from 0 to 99 ;Sum of odd numbers from 0 to 99 (0..99). (reduce select { |n| odd? n }. + inject(0) { |acc, n| acc + n } (filter odd? (range 100))) => 2500 => 2500
  • 9. Functional, but lazy Ruby Clojure def odd_trace?(n) (defn odd-trace? [n] puts n (print n) (n % 2) == 1 (= 1 (mod n 2))) end #Sum of odd numbers from 0 to 9 ;Sum of odd numbers from 0 to 9 (0..99). (reduce + select { |n| odd_trace? n }. (take 10 first(10). (filter odd-trace? (range 100)))) inject(0) { |acc, n| acc + n } => prints 0 to 99, returns 100 => prints 0 to 31, returns 100
  • 10. Immutable data structure Data structure are always immutable. Adding or removing an element to an array, vector, hash or set will always return a new collection. But, they are efficient because they are persistant (in the sense that they share structure.)
  • 11. Concurrency Software transactional memory Or having multiple threads access the same reference using transactions instead of locks. STMs are not all the same (like GC) Readers are never blocked. Works hand in hand with persistant data structure.
  • 12. Ref 1 @A A 2 @A 3
  • 13. Where did my books go? (def book1 { :author "David Flanagan" :title "The Ruby Programming language" }) (def book2 { :author "Gregory Brown" :title "Ruby Best Practices"}) (def home-books (ref #{book1 book2})) (def lent-books (ref #{})) (alter home-books disj book1) => No transaction running (dosync (alter home-books disj book1) (alter lent-books conj book1)) @home-books => #{{:author "Gregory Brown", :title "Ruby Best Practices"}} @lent-books => #{{:author "David Flanagan", :title "The Ruby Programming language"}}
  • 14. Further exploration If nothing else: Are we there yet? Main site: Clojure.org News & getting started: Disclojure Books (a comparison) ●Programming Clojure ●Clojure in Action ●The Joy of Clojure ●Practical Clojure ●And one upcoming from O'Reilly