SlideShare a Scribd company logo
Scala clojure techday_2011
Functional Programming
          on the JVM with
          Scala and Clojure
            What they are and why you should care


      Cristiano Breuel                         Thadeu Russo
Advisory Software Engineer              Advisory Software Engineer
   (cbreuel@br.ibm.com)                   (thadeurc@br.ibm.com)
Y = λf.(λx.f (x x)) (λx.f (x x))
Y = λf.(λx.f (x x)) (λx.f (x x))
What is functional programming
            about?
Lambda calculus (a.k.a λ-calculus)

  function definition

  function application

  recursion
Scala clojure techday_2011
Referential Integrity

  Avoids state and mutable data

Higher-Order functions:

  Functions can receive and return other
  functions

Lazy Evaluation:

  Evaluate an expression only when
  necessary
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
FP has been around since the 1950’s

   Why it is becoming more important now?
FP has been around since the 1950’s

   Why it is becoming more important now?
FP has been around since the 1950’s

   Why it is becoming more important now?




                Why should I care?
Because of them...
Because of them...



... the multi-core processors
Because of them...



... the multi-core processors

    (also, to become a smarter
             developer!)
On the other side...
On the other side...


 The JVM is cool!
JVM -> Java Language

Huge investment already on the JVM
(libraries, middleware, performance, GC,
remote communication, etc..)

JVM executes byte-code
The question is:
The question is:


    Why not create new (functional)
     languages on top of the JVM?
Scala clojure techday_2011
(not Closure)
Clojure has...
Clojure has...
... tight integration with the JVM and Java
Clojure has...
... tight integration with the JVM and Java

... compilation for performance
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections

... lazy sequences
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections

... lazy sequences

... primitives for concurrency (STM, agents)
Clojure is a LISP
Clojure is a LISP


  (Lots of (Irritating
(Stupid (Parentheses))))
Clojure is a LISP


  (Lots of (Irritating
(Stupid (Parentheses))))



    a.k.a. List Processing
LISP
LISP


Homoiconicity - code is data
LISP


Homoiconicity - code is data

Macros
LISP


Homoiconicity - code is data

Macros

Multiple dispatch (multi-methods)
Syntax
              Operands
Operator     (arguments)


(str "Hello" "World")

           Expression
           delimiters
Syntax

["red" "green" "blue"]               Array

{:color "blue" :length 2}              Map

:color                             Keyword

#(even? %)               Anonymous function
Higher-Order Functions
Efficient Immutable
    Collections
Lazy Sequences
import java.util.HashMap;
import java.util.Map;



public class ColorMapper {

	   private static String[] COLORS = {"white", "blue"};
	
	   public static Map<String, String> mapLineColors(String[] values) {
	   	   Map<String, String> retVal = new HashMap<String, String>();
	   	   int i = 0;
	   	   for (String value: values) {
	   	   	    retVal.put(value, COLORS[i % COLORS.length]);
	   	   	    i++;
	   	   }
	   	   return retVal;
	   }
	
	   public static void main(String[] args) {
	   	
	   	   String[] values = {"Clojure", "Java", "Scala", "Visual Basic"};
	   	
	   	   System.out.println(mapLineColors(values));
	   }
	
}
Java Integration

(def now (new java.util.Date))

(def now (java.util.Date.))

(. now getTime)

(doto (JFrame.)
  (. add (JLabel. "Hello, Clojure!"))
  (. pack)
  (. show))
sample
Scala
Fast

Functional

Expressive

Statically typed (with type inference)

Concurrent
every value is an object

vals / vars

traits

companion objects

currying

closures / high order functions

pattern matching / case classes

XML literals

Lazy evaluation, and much more...
sample
To sum up...
Scala clojure techday_2011
We cannot choose our problems....

  .... but we can choose our tools.

It is our responsibility to figure out
           the “right” tool.
Even if you can't use
these languages in your
  day job yet, learning
 them will make you a
  better programmer!
References



http://clojure.org/

http://www.scala-lang.org/
Scala clojure techday_2011
Scala clojure techday_2011

More Related Content

PDF
Kotlin Overview
PDF
Clojure made-simple - John Stevenson
PDF
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
PDF
Building a Tagless Final DSL for WebGL
PDF
Reactive Programming in the Browser feat. Scala.js and PureScript
PDF
Taking Kotlin to production, Seriously
PDF
Ankara Jug - Practical Functional Programming with Scala
PDF
Introduction to Functional Programming with Scala
Kotlin Overview
Clojure made-simple - John Stevenson
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Building a Tagless Final DSL for WebGL
Reactive Programming in the Browser feat. Scala.js and PureScript
Taking Kotlin to production, Seriously
Ankara Jug - Practical Functional Programming with Scala
Introduction to Functional Programming with Scala

What's hot (20)

PDF
Introduction to kotlin
PDF
Functional Programming in Scala
PDF
Clojure, Plain and Simple
PDF
Quick introduction to scala
PPT
Oscon keynote: Working hard to keep it simple
PDF
Scala eXchange opening
KEY
Scala: functional programming for the imperative mind
PDF
Functional Programming In Practice
PPTX
Scala - The Simple Parts, SFScala presentation
PPTX
Introduction to Kotlin Language and its application to Android platform
PDF
Swift and Kotlin Presentation
PDF
Aggregate Programming in Scala
PDF
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
PDF
Generics Past, Present and Future
PDF
scalaliftoff2009.pdf
PPTX
Kotlin presentation
PPTX
Intro to Akka Streams
PDF
Generics Past, Present and Future (Latest)
PPTX
Systematic Generation Data and Types in C++
PDF
Collections forceawakens
Introduction to kotlin
Functional Programming in Scala
Clojure, Plain and Simple
Quick introduction to scala
Oscon keynote: Working hard to keep it simple
Scala eXchange opening
Scala: functional programming for the imperative mind
Functional Programming In Practice
Scala - The Simple Parts, SFScala presentation
Introduction to Kotlin Language and its application to Android platform
Swift and Kotlin Presentation
Aggregate Programming in Scala
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Generics Past, Present and Future
scalaliftoff2009.pdf
Kotlin presentation
Intro to Akka Streams
Generics Past, Present and Future (Latest)
Systematic Generation Data and Types in C++
Collections forceawakens
Ad

Similar to Scala clojure techday_2011 (20)

PDF
Short intro to scala and the play framework
PDF
A Sceptical Guide to Functional Programming
PDF
Pune Clojure Course Outline
PDF
Clojure intro
PDF
Clojure and The Robot Apocalypse
PPTX
Clojure And Swing
PDF
Clojure - A new Lisp
ODP
Functional Programming With Scala
PPTX
Concurrency Constructs Overview
PDF
Introduction to clojure
PDF
SE 20016 - programming languages landscape.
KEY
JavaScript Growing Up
PDF
Hadoop + Clojure
KEY
Scala Introduction
ODP
Functional programming with Scala
PPT
ODP
Clojure
PDF
Hw09 Hadoop + Clojure
ODP
PPT
Scala Talk at FOSDEM 2009
Short intro to scala and the play framework
A Sceptical Guide to Functional Programming
Pune Clojure Course Outline
Clojure intro
Clojure and The Robot Apocalypse
Clojure And Swing
Clojure - A new Lisp
Functional Programming With Scala
Concurrency Constructs Overview
Introduction to clojure
SE 20016 - programming languages landscape.
JavaScript Growing Up
Hadoop + Clojure
Scala Introduction
Functional programming with Scala
Clojure
Hw09 Hadoop + Clojure
Scala Talk at FOSDEM 2009
Ad

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PPT
Teaching material agriculture food technology
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
Assigned Numbers - 2025 - Bluetooth® Document
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Teaching material agriculture food technology
A comparative analysis of optical character recognition models for extracting...
Machine Learning_overview_presentation.pptx
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Scala clojure techday_2011

Editor's Notes

  • #2: \n
  • #3: Thadeu e Cristiano: Apresenta&amp;#xE7;&amp;#xE3;o dos palestrantes\n
  • #4: Thadeu: Apenas assustar o pessoal - dizer que precisamos antes entender o combinador Y\n
  • #5: Thadeu: slide apenas de passagem, sem muitos comentarios.\n
  • #6: Thadeu: basicamente ler o slide.\n
  • #7: Thadeu: da wikipedia: is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.\nenfatiza a aplicacao de funcoes ao contrario da mudanca de estado, como eh feito em linguagens interativas\n
  • #8: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #9: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #10: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #11: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #12: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #13: Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  • #14: Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo n&amp;#xE3;o academico\n
  • #15: Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo n&amp;#xE3;o academico\n
  • #16: Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  • #17: Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  • #18: Thadeu passa para Cristiano.\n
  • #19: Cristiano:\n
  • #20: Cristiano:\n
  • #21: Cristiano:\n
  • #22: Cristiano:\n
  • #23: Cristiano:\n
  • #24: Cristiano:\n
  • #25: Cristiano:\n
  • #26: Cristiano:\n
  • #27: Cristiano:\n
  • #28: Cristiano:\n
  • #29: Cristiano:\n
  • #30: Cristiano:\n
  • #31: Cristiano:\n
  • #32: Cristiano:\n
  • #33: Cristiano:\n
  • #34: Cristiano:\n
  • #35: \n
  • #36: \n
  • #37: \n
  • #38: \n
  • #39: \n
  • #40: Thadeu: Comentar cada um dos itens acima (dizer tbm q eh menos verborragica que java) - veremos exemplo\n
  • #41: Thadeu: ir para o repl e fazer alguns exemplos destes caras\nval\nfunction as objects\nreduceLeft - usar as chaves e fazer o currying\n\n\nsobre a parte de lazy - comentar que nao existem lazy collections assim como em haskell ou closure, porem\nda para criar metodos que fazer conversoes de modo lazy (usando iteradores)\n
  • #42: Thadeu: Converter codigo java para scala\n
  • #43: \n
  • #44: \n
  • #45: \n
  • #46: \n
  • #47: \n
  • #48: \n
  • #49: \n