SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

Введение в 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
 

Destacado (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 a 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 a 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
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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?Igalia
 
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 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
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 CVKhem
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 organizationRadu Cotescu
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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?
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

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