SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
From Lisp to Clojure/Incanter and R
             An Introduction




             Shane M. Conway
              January 7, 2010
“Back to the Future”
• The goal of this presentation is to draw some rough
  comparisons between Incanter and R.
• There has been a not insubstantial amount of discussion over
  the “future of R”.
• Ross Ihaka, a co-creater of R, has been especially vocal over
  his concerns of R’s performance (see his homepage for more
  detail). In “Back to the Future: Lisp as a Base for a Statistical
  Computing System” (August 2008) Ihaka and Duncan Temple
  Lang (of UC Davis and Omegahat) state:
      “The application of cutting-edge statistical methodology is limited by the capabilities of
      the systems in which it is implemented. In particular, the limitations of R mean that
      applications developed there do not scale to the larger problems of interest in practice.
      We identify some of the limitations of the computational model of the R language that
      reduces its effectiveness for dealing with large data efficiently in the modern era.
        We propose developing an R-like language on top of a Lisp-based engine for statistical
      computing that provides a paradigm for modern challenges and which leverages the
      work of a wider community.”
Lisp and Fortran
• Modern programming languages began primarily with two
  languages that had different philosophies and goals: Fortran
  and Lisp. They came from different sides of academia:
   – Physicists and engineers wanted numeric computations to be run
     in the most efficient way to solve concrete problems
   – Mathematicians were interested in algorithmic research for solving
     more abstract problems
• Both R and Clojure are based on the Lisp model of “functional
  programming” where everything is treated as an object.
• The name Lisp comes from "list processing," and it is
  sometimes said that everything in Lisp is a list.
Timeline
• Looking at the history of programming languages is complex,
  as new languages tend to be informed by all prior
  developments.

• 1950/60s: Fortran (54), Lisp (58), Cobol (59), APL (62), Basic
  (64)
• 1970s: Pascal (70), C (72), S (75), SQL (78)
• 1980s: C++ (83), Erlang (86), Perl (87)
• 1990s: Haskell (90), Python (91), Java (91), R (93), Ruby (93),
  Common Lisp (94), PHP (95)
• 2000s: C# (00), Scala (03), Groovy (04), F# (05), Clojure (07),
  Go (09)
R
• S began as a project at Bell Laboratories in 1975, involving
  John Chambers, Rick Becker, Doug Dunn, Paul Tukey, and
  Graham Wilkinson.
• R is a “Scheme-like” language. R is written primarily in C and
  Fortran, although it is being extended through other
  languages (e.g. Java).
JVM
• The Java Virtual Machine (JVM) is very similar in theory to the
  Common Language Runtime (CLR) for the .Net framework: it
  provides a virtual machine for the execution of programs.
• Offers memory and other resource management (garbage
  collection), JIT, a type system.
• JVM was designed for Java, but it operates on Java bytecode
  so it can be used by other languages such as Jython, JRuby,
  Groovy, Scala, and Clojure.
Clojure
• Clojure is a Lisp language that runs on the JVM. It was
  released in 1997 by Rich Hickey, who continues to be the
  primary contributor.
   – “Clojure (pronounced like closure) is a modern dialect of the Lisp
     programming language. It is a general-purpose language supporting
     interactive development that encourages a functional programming
     style, and simplifies multithreaded programming. Clojure runs on the
     Java Virtual Machine and the Common Language Runtime. Clojure
     honors the code-as-data philosophy and has a sophisticated Lisp
     macro system.”
• Clojure can be used interactively (REPL) or compiled and
  deployed as an executable. REPL stands for “read-eval-print
  loop”.
Incanter
• Incanter is a Clojure-based, R-like platform for statistical
  computing and graphics, created by David Edgar Liebke.
   – Incanter “leverages both the power of Clojure, a dynamically-typed,
     functional programming language, and the rich set of libraries
     available on the JVM for accessing, processing, and visualizing data. At
     its core are the Parallel Colt numerics library, a multithreaded version
     of Colt, the JFreeChart charting library, the Processing visualization
     library, as well as several other Java and Clojure libraries.”
• http://www.jstatsoft.org/v13 “Lisp-Stat, Past, Present and
  Future” in Journal of Statistical Software Vol. 13, Dec. 2004
• Why Incanter? The primary reason is easy access to Java.
Comparison
Similarities:                    Differences:
• They can both be used          • R requires more effort to
   interactively (for Clojure:      integrate with Java
   REPL)                         • R influenced more by C and
• They are both functional,         Fortran
   based on Scheme               • Clojure can be compiled
• Both languages have type       • Clojure is not OO, while R
   inference                        has S3, S4, and r.oo
• “Code as data”                 • Clojure has many more data
                                    types
                                 • R is more of a DSL
Tradeoffs
Advantages:                       Disadvantages
• Clojure runs on the JVM, so     • Incanter is very immature in
  it can reference any Java          comparison; there is no
  library, and can be called by      equivalent to CRAN
  other languages on the JVM      • Clojure has 339 questions
• Clojure natively deals with        on stackoverflow compared
  concurrency                        to 562 for R
• Vectors/Lists/etc. in Clojure   • Clojure/Incanter are each
  allow you to add/remove            primarily developed by 1
                                     person; no Core team
Using Clojure/Incanter
• Clojure is a set of jars, so it can be used from the command
  line by calling java.
• To use Incanter, just load the desired library into a Clojure
  session:
   – (use '(incanter core stats charts))
• Many IDE options:
   – I use Eclipse for all my development (R: StatET, Python: Pydev, C/C++:
     CDT: http://code.google.com/p/counterclockwise/ and
     http://www.ibm.com/developerworks/opensource/library/os-eclipse-
     clojure/index.html
   – Using Emacs: http://incanter-blog.org/2009/12/20/getting-started/
Hello World
• R takes syntax from both Lisp and C.

  // Java
  public void hello(String name) {
        System.out.println("Hello, " + name);
  }

  ; Clojure
  (defn hello [name]
         (println "Hello," name))

  #R
  hello <- function(name) {
         print(paste("Hello,“, name))
  }
Basic Syntax
Statements in R use more of a C-   (+ 1 2) ; => 3           `+`(1,2) # => 3
like syntax                        (range 3) ; => (1 2 3)   seq(1,3) # => (1 2 3)
Getting help                       (doc functionname)       help(functionname)
Checking an object type            (type objectname)        class(objectname)
Timing performance                 (time functioncall)      System.time(functioncall)
Browsing the workspace             (ns-publics 'user)       ls()
Nagivating the workspace           (all-ns)                 search()
Collections
Lists                               [def stooges ["Moe" "Larry"            stooges <- c(“Moe”, “Larry”,
                                    "Curly" "Shemp"]]                      “Curly”, “Shemp”)
Vectors                             (def stooges ["Moe" "Larry"            stooges <- c(“Moe”, “Larry”,
                                    "Curly" "Shemp"])                      “Curly”, “Shemp”)

Maps                                (def popsicle-map                      popsicle.map <-
                                     {:red :cherry, :green :apple,         list(“red”=“cherry”,
                                    :purple :grape})                       “green”=“apply”,
                                    def popsicle-map                       “purple”=“grape”)
                                     (sorted-map :red :cherry, :green
                                    :apple, :purple :grape))
Matrix (does not exist as part of   (def A (matrix [[1 2 3] [4 5 6] [7 8   A <- matrix(1:9, nrow=3)
Clojure)                            9]]))
                                    (def A2 (matrix [1 2 3 4 5 6 7 8 9]
                                    3))
Count                               (count stooges)                        length(stooges)
Filtering                           (filter #(> (count %) 3) stooges)      stooges[nchar(stooges)==3]
                                    (some #(= % "Moe") stooges)            stooges*stooges==“Moe”+
Matrices
Matrix (does not exist as part of   (def A (matrix [[1 2 3] [4 5 6] [7 8   A <- matrix(1:9, nrow=3)
Clojure)                            9]]))
                                    (def A2 (matrix [1 2 3 4 5 6 7 8 9]
                                    3))
Dimensions                          (dim A)                                dim(a)
                                    (ncol A)                               ncol(a)
                                    (nrow A)                               nrow(a)
Filtering                           (use 'incanter.datasets)               iris[1,1]
                                    (def iris (to-matrix (get-dataset      Iris[,-1]
                                    :iris)))
                                    (sel iris 0 0)
                                    (sel iris :rows 0 :cols 0)
                                    (sel iris :except-cols 1)
Statistics
Quantile      (quantile (range 10))           quantile(1:10)
Sampling      (sample (range 100) :size 10)   sample(1:100, 10)
Mean          (mean (range 10))               mean(1:10)
Skewness      (skewness (range 10))           moments::skewness(rnorm(100)
                                              )
Regression    (linear-model y x)              lm(y ~ x)
Correlation   (correlation x y)               cor(x, y)
              (correlation matrix)            cor(x)
Loops
• Several different ways to loop in     • Some examples of the same
  Clojure:                                sequence in R:

    ;; Version 1                           for(i in seq(1, 20, 2)) print(i)
    (loop [i 1]
      (when (< i 20)                    • R also makes heavy usage of the
       (println i)                        apply family of functions (Clojure
       (recur (+ 2 i))))                  also has an apply function):

    ;; Version 2                           sapply(seq(1, 20, 2), print)
    (dorun (for [i (range 1 20 2)]
          (println i)))                 • R also has a while() function.

    ;; Version 3
    (doseq [i (range 1 20 2)]
      (println i))
Java and Clojure
• Clojure interacts with Java seamlessly. A trivial example:

  (. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))


• Or a slightly more advanced example:

   (defn fetch-xml [uri]
    (xml-zip
     (parse
      (org.xml.sax.InputSource.
       (java.io.StringReader.
        (slurp* (java.net.URI. (re-gsub #"s+" "+" (str uri)))))))))
R and Java: RJava
• Calling Java code from R (and vice versa) can be done with the
  RJava package and JRI.
  #R
  helloJavaWorld <- function(){
    hjw <- .jnew("HelloJavaWorld") # create instance of class
    out <- .jcall(hjw, "S", "sayHello") # invoke sayHello method
    return(out)
  }

  // Java
  public class HelloJavaWorld {
           public String sayHello() {
                         String result = new String("Hello Java World!");
                         return result;
           }
           public static void main(String[] args) {
           }
  }
Java and R: JRI
• JRI allows you to pass R commands to an R console and get
  results back:
  import org.rosuda.JRI.Rengine;
  ...

         Rengine re=new Rengine(args, false, new Rexecutor());
         REXP x;
         re.eval("data(iris)",false);
         System.out.println(x=re.eval("iris"));
         RVector v = x.asVector();
         if (v.getNames()!=null) {
                     System.out.println("has names:");
                     for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
                                   System.out.println(e.nextElement());
                     }
         }
Performance
• Problem Number 1 from Project Euler: “Find the sum of all
  the multiples of 3 or 5 below 1000.” I just changed this to
  be a count instead:
user=> (defn divisible-by-3-or-5? [num]   divby3or5 <- function(n) {
   (or (== (mod num 3) 0)(== (mod num         n[(n %% 3) == 0 | (n %% 5) == 0]
   5) 0)))                                }
user=> (time (println (count (filter      system.time(print(length(divby3or5(1:10
    divisible-by-3-or-5? (range               000000))))
    10000000)))))
4666667                                   [1] 4666667
"Elapsed time: 29321.981146 msecs"          user system elapsed
nil                                        12.21 0.22 12.70

• This is a trivial example, but R significantly outperformed
  on this simple operation.
• A more thorough benchmarking of Incantor is necessary.
Final Thoughts
• Clojure/Incanter is a very promising programming language
  based on Lisp. It provides functional programming with a
  seamless Java integration and native concurrency.
• R has a remarkable user community of dedicated scientists
  and mathematicians which is continuing to grow.
  Performance issues can be mitigated by using parallelization
  (e.g. MPI), and there are efforts to create compilers that
  promise 10x speed improvements.
• Incanter can be used in the place of R for projects that use
  relatively basic statistics, and that have a reliance on Java
  (especially for something that is web-based).
Resources
Some useful resources for Clojure/Incanter
• http://clojure.org/
• http://incanter.org/
• http://java.ociweb.com/mark/clojure/article.html
• http://en.wikibooks.org/wiki/Clojure_Programming/

For R:
• http://r-project.org and http://cran.r-project.org
• http://www.stats.uwo.ca/faculty/murdoch/2864/Flourish.pdf

Lastly, http://rosettacode.org/ has good examples for both
   languages.

Más contenido relacionado

La actualidad más candente

R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011Mandi Walls
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinDmitry Pranchuk
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexityIntro C# Book
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat SheetGlowTouch
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196Mahmoud Samir Fayed
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturialWayne Tsai
 
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageCoscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageWayne Tsai
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 

La actualidad más candente (20)

Nx tutorial basics
Nx tutorial basicsNx tutorial basics
Nx tutorial basics
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
core.logic introduction
core.logic introductioncore.logic introduction
core.logic introduction
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196
 
V8
V8V8
V8
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageCoscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 

Similar a From Lisp to Clojure/Incanter and RAn Introduction

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々ScalaプログラミングTomoharu ASAMI
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
Scala clojure techday_2011
Scala clojure techday_2011Scala clojure techday_2011
Scala clojure techday_2011Thadeu Russo
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure/conj 2017
Clojure/conj 2017Clojure/conj 2017
Clojure/conj 2017Darren Kim
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageNeo4j
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
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 ParadigmsMiles Sabin
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
Introducing redis
Introducing redisIntroducing redis
Introducing redisNuno Caneco
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.Ruslan Shevchenko
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture EMC
 
Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersVitomir Kovanovic
 
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
 

Similar a From Lisp to Clojure/Incanter and RAn Introduction (20)

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
Scala clojure techday_2011
Scala clojure techday_2011Scala clojure techday_2011
Scala clojure techday_2011
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure/conj 2017
Clojure/conj 2017Clojure/conj 2017
Clojure/conj 2017
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
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
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Introducing redis
Introducing redisIntroducing redis
Introducing redis
 
Clojure
ClojureClojure
Clojure
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture
 
Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics Researchers
 
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
 

Más de elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makeselliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 
FleetDB A Schema-Free Database in Clojure
FleetDB A Schema-Free Database in ClojureFleetDB A Schema-Free Database in Clojure
FleetDB A Schema-Free Database in Clojureelliando dias
 

Más de elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 
FleetDB A Schema-Free Database in Clojure
FleetDB A Schema-Free Database in ClojureFleetDB A Schema-Free Database in Clojure
FleetDB A Schema-Free Database in Clojure
 

Último

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 

Último (20)

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 

From Lisp to Clojure/Incanter and RAn Introduction

  • 1. From Lisp to Clojure/Incanter and R An Introduction Shane M. Conway January 7, 2010
  • 2. “Back to the Future” • The goal of this presentation is to draw some rough comparisons between Incanter and R. • There has been a not insubstantial amount of discussion over the “future of R”. • Ross Ihaka, a co-creater of R, has been especially vocal over his concerns of R’s performance (see his homepage for more detail). In “Back to the Future: Lisp as a Base for a Statistical Computing System” (August 2008) Ihaka and Duncan Temple Lang (of UC Davis and Omegahat) state: “The application of cutting-edge statistical methodology is limited by the capabilities of the systems in which it is implemented. In particular, the limitations of R mean that applications developed there do not scale to the larger problems of interest in practice. We identify some of the limitations of the computational model of the R language that reduces its effectiveness for dealing with large data efficiently in the modern era. We propose developing an R-like language on top of a Lisp-based engine for statistical computing that provides a paradigm for modern challenges and which leverages the work of a wider community.”
  • 3. Lisp and Fortran • Modern programming languages began primarily with two languages that had different philosophies and goals: Fortran and Lisp. They came from different sides of academia: – Physicists and engineers wanted numeric computations to be run in the most efficient way to solve concrete problems – Mathematicians were interested in algorithmic research for solving more abstract problems • Both R and Clojure are based on the Lisp model of “functional programming” where everything is treated as an object. • The name Lisp comes from "list processing," and it is sometimes said that everything in Lisp is a list.
  • 4. Timeline • Looking at the history of programming languages is complex, as new languages tend to be informed by all prior developments. • 1950/60s: Fortran (54), Lisp (58), Cobol (59), APL (62), Basic (64) • 1970s: Pascal (70), C (72), S (75), SQL (78) • 1980s: C++ (83), Erlang (86), Perl (87) • 1990s: Haskell (90), Python (91), Java (91), R (93), Ruby (93), Common Lisp (94), PHP (95) • 2000s: C# (00), Scala (03), Groovy (04), F# (05), Clojure (07), Go (09)
  • 5. R • S began as a project at Bell Laboratories in 1975, involving John Chambers, Rick Becker, Doug Dunn, Paul Tukey, and Graham Wilkinson. • R is a “Scheme-like” language. R is written primarily in C and Fortran, although it is being extended through other languages (e.g. Java).
  • 6. JVM • The Java Virtual Machine (JVM) is very similar in theory to the Common Language Runtime (CLR) for the .Net framework: it provides a virtual machine for the execution of programs. • Offers memory and other resource management (garbage collection), JIT, a type system. • JVM was designed for Java, but it operates on Java bytecode so it can be used by other languages such as Jython, JRuby, Groovy, Scala, and Clojure.
  • 7. Clojure • Clojure is a Lisp language that runs on the JVM. It was released in 1997 by Rich Hickey, who continues to be the primary contributor. – “Clojure (pronounced like closure) is a modern dialect of the Lisp programming language. It is a general-purpose language supporting interactive development that encourages a functional programming style, and simplifies multithreaded programming. Clojure runs on the Java Virtual Machine and the Common Language Runtime. Clojure honors the code-as-data philosophy and has a sophisticated Lisp macro system.” • Clojure can be used interactively (REPL) or compiled and deployed as an executable. REPL stands for “read-eval-print loop”.
  • 8. Incanter • Incanter is a Clojure-based, R-like platform for statistical computing and graphics, created by David Edgar Liebke. – Incanter “leverages both the power of Clojure, a dynamically-typed, functional programming language, and the rich set of libraries available on the JVM for accessing, processing, and visualizing data. At its core are the Parallel Colt numerics library, a multithreaded version of Colt, the JFreeChart charting library, the Processing visualization library, as well as several other Java and Clojure libraries.” • http://www.jstatsoft.org/v13 “Lisp-Stat, Past, Present and Future” in Journal of Statistical Software Vol. 13, Dec. 2004 • Why Incanter? The primary reason is easy access to Java.
  • 9. Comparison Similarities: Differences: • They can both be used • R requires more effort to interactively (for Clojure: integrate with Java REPL) • R influenced more by C and • They are both functional, Fortran based on Scheme • Clojure can be compiled • Both languages have type • Clojure is not OO, while R inference has S3, S4, and r.oo • “Code as data” • Clojure has many more data types • R is more of a DSL
  • 10. Tradeoffs Advantages: Disadvantages • Clojure runs on the JVM, so • Incanter is very immature in it can reference any Java comparison; there is no library, and can be called by equivalent to CRAN other languages on the JVM • Clojure has 339 questions • Clojure natively deals with on stackoverflow compared concurrency to 562 for R • Vectors/Lists/etc. in Clojure • Clojure/Incanter are each allow you to add/remove primarily developed by 1 person; no Core team
  • 11. Using Clojure/Incanter • Clojure is a set of jars, so it can be used from the command line by calling java. • To use Incanter, just load the desired library into a Clojure session: – (use '(incanter core stats charts)) • Many IDE options: – I use Eclipse for all my development (R: StatET, Python: Pydev, C/C++: CDT: http://code.google.com/p/counterclockwise/ and http://www.ibm.com/developerworks/opensource/library/os-eclipse- clojure/index.html – Using Emacs: http://incanter-blog.org/2009/12/20/getting-started/
  • 12. Hello World • R takes syntax from both Lisp and C. // Java public void hello(String name) { System.out.println("Hello, " + name); } ; Clojure (defn hello [name] (println "Hello," name)) #R hello <- function(name) { print(paste("Hello,“, name)) }
  • 13. Basic Syntax Statements in R use more of a C- (+ 1 2) ; => 3 `+`(1,2) # => 3 like syntax (range 3) ; => (1 2 3) seq(1,3) # => (1 2 3) Getting help (doc functionname) help(functionname) Checking an object type (type objectname) class(objectname) Timing performance (time functioncall) System.time(functioncall) Browsing the workspace (ns-publics 'user) ls() Nagivating the workspace (all-ns) search()
  • 14. Collections Lists [def stooges ["Moe" "Larry" stooges <- c(“Moe”, “Larry”, "Curly" "Shemp"]] “Curly”, “Shemp”) Vectors (def stooges ["Moe" "Larry" stooges <- c(“Moe”, “Larry”, "Curly" "Shemp"]) “Curly”, “Shemp”) Maps (def popsicle-map popsicle.map <- {:red :cherry, :green :apple, list(“red”=“cherry”, :purple :grape}) “green”=“apply”, def popsicle-map “purple”=“grape”) (sorted-map :red :cherry, :green :apple, :purple :grape)) Matrix (does not exist as part of (def A (matrix [[1 2 3] [4 5 6] [7 8 A <- matrix(1:9, nrow=3) Clojure) 9]])) (def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) Count (count stooges) length(stooges) Filtering (filter #(> (count %) 3) stooges) stooges[nchar(stooges)==3] (some #(= % "Moe") stooges) stooges*stooges==“Moe”+
  • 15. Matrices Matrix (does not exist as part of (def A (matrix [[1 2 3] [4 5 6] [7 8 A <- matrix(1:9, nrow=3) Clojure) 9]])) (def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) Dimensions (dim A) dim(a) (ncol A) ncol(a) (nrow A) nrow(a) Filtering (use 'incanter.datasets) iris[1,1] (def iris (to-matrix (get-dataset Iris[,-1] :iris))) (sel iris 0 0) (sel iris :rows 0 :cols 0) (sel iris :except-cols 1)
  • 16. Statistics Quantile (quantile (range 10)) quantile(1:10) Sampling (sample (range 100) :size 10) sample(1:100, 10) Mean (mean (range 10)) mean(1:10) Skewness (skewness (range 10)) moments::skewness(rnorm(100) ) Regression (linear-model y x) lm(y ~ x) Correlation (correlation x y) cor(x, y) (correlation matrix) cor(x)
  • 17. Loops • Several different ways to loop in • Some examples of the same Clojure: sequence in R: ;; Version 1 for(i in seq(1, 20, 2)) print(i) (loop [i 1] (when (< i 20) • R also makes heavy usage of the (println i) apply family of functions (Clojure (recur (+ 2 i)))) also has an apply function): ;; Version 2 sapply(seq(1, 20, 2), print) (dorun (for [i (range 1 20 2)] (println i))) • R also has a while() function. ;; Version 3 (doseq [i (range 1 20 2)] (println i))
  • 18. Java and Clojure • Clojure interacts with Java seamlessly. A trivial example: (. javax.swing.JOptionPane (showMessageDialog nil "Hello World")) • Or a slightly more advanced example: (defn fetch-xml [uri] (xml-zip (parse (org.xml.sax.InputSource. (java.io.StringReader. (slurp* (java.net.URI. (re-gsub #"s+" "+" (str uri)))))))))
  • 19. R and Java: RJava • Calling Java code from R (and vice versa) can be done with the RJava package and JRI. #R helloJavaWorld <- function(){ hjw <- .jnew("HelloJavaWorld") # create instance of class out <- .jcall(hjw, "S", "sayHello") # invoke sayHello method return(out) } // Java public class HelloJavaWorld { public String sayHello() { String result = new String("Hello Java World!"); return result; } public static void main(String[] args) { } }
  • 20. Java and R: JRI • JRI allows you to pass R commands to an R console and get results back: import org.rosuda.JRI.Rengine; ... Rengine re=new Rengine(args, false, new Rexecutor()); REXP x; re.eval("data(iris)",false); System.out.println(x=re.eval("iris")); RVector v = x.asVector(); if (v.getNames()!=null) { System.out.println("has names:"); for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) { System.out.println(e.nextElement()); } }
  • 21. Performance • Problem Number 1 from Project Euler: “Find the sum of all the multiples of 3 or 5 below 1000.” I just changed this to be a count instead: user=> (defn divisible-by-3-or-5? [num] divby3or5 <- function(n) { (or (== (mod num 3) 0)(== (mod num n[(n %% 3) == 0 | (n %% 5) == 0] 5) 0))) } user=> (time (println (count (filter system.time(print(length(divby3or5(1:10 divisible-by-3-or-5? (range 000000)))) 10000000))))) 4666667 [1] 4666667 "Elapsed time: 29321.981146 msecs" user system elapsed nil 12.21 0.22 12.70 • This is a trivial example, but R significantly outperformed on this simple operation. • A more thorough benchmarking of Incantor is necessary.
  • 22. Final Thoughts • Clojure/Incanter is a very promising programming language based on Lisp. It provides functional programming with a seamless Java integration and native concurrency. • R has a remarkable user community of dedicated scientists and mathematicians which is continuing to grow. Performance issues can be mitigated by using parallelization (e.g. MPI), and there are efforts to create compilers that promise 10x speed improvements. • Incanter can be used in the place of R for projects that use relatively basic statistics, and that have a reliance on Java (especially for something that is web-based).
  • 23. Resources Some useful resources for Clojure/Incanter • http://clojure.org/ • http://incanter.org/ • http://java.ociweb.com/mark/clojure/article.html • http://en.wikibooks.org/wiki/Clojure_Programming/ For R: • http://r-project.org and http://cran.r-project.org • http://www.stats.uwo.ca/faculty/murdoch/2864/Flourish.pdf Lastly, http://rosettacode.org/ has good examples for both languages.