SlideShare a Scribd company logo
Clojure and Modularity

    Philly Lambda
Tuesday, July 21, 2009

      Stuart Sierra
http://stuartsierra.com/
www.altlaw.org
Clojure's Four Elements
List     (print :hello "Philly")

Vector [:eat "Pie" 3.14159]

Map      {:lisp 1   "The Rest" 0}

Set      #{2 1 3 5 "Eureka"}
defn
(defn greet [name]
  (println "Hello," name))

(defn average [& args]
  (/ (reduce + args) (count args)))
Data are Functions
({:f "foo" :b "bar"} :f)
"foo"

(:key {:key "value", :x "y"})
"value"

([:a :b :c] 2)
:c

(#{1 5 3} 3)
true
defmacro

(defmacro when [test & body]
  (list 'if test (cons 'do body)))
Java
(import '(com.example.package
            MyClass YourClass))

(.method object argument)

(MyClass/staticMethod argument)

(MyClass. argument)
synchronous   asynchronous


coordinated      ref

independent     atom         agent

unshared         var
Vars
(def life 42)

(defn meaning [] (println life))

(meaning)
42

(binding [life 37]     (let [life 37]
                          (println life)
  (meaning))              (meaning))
37                     37
                       42
Refs
(def c (ref 100))

(deref c)
100

(dosync (alter c inc))

(deref c)
101
Agents
(def fib (agent [1 1 2]))

(deref fib)
[1 1 2]

(send fib conj 3 5)   returns immediately!

 later on...
(deref fib)
[1 1 2 3 5]
clojure.contrib.http.agent
(http-agent
   "http://www.altlaw.org/"
   :on-success
     (fn [a]
       (println
         (response-body-str a))))
Multimethods
(defmulti copy
   (fn [in out]
     [(class in) (class out)]))
Multimethods
(defmethod copy [InputStream OutputStream] ..
(defmethod copy [InputStream Writer] ...
(defmethod copy [InputStream File] ...
(defmethod copy [Reader OutputStream] ...
(defmethod copy [Reader Writer] ...
(defmethod copy [Reader File] ...
(defmethod copy [File OutputStream] ...
(defmethod copy [File Writer] ...
(defmethod copy [File File] ...
Namespaces
(ns my.cool.project
  (:require [clojure.contrib.math :as math])
  (:import (java.math BigDecimal)))


(defn lower-median [x y]
  (math/floor (/ x y))
Modularity and
     Dependency Management
●   CPAN          ●   OSGi
●   Python Eggs   ●   Maven
●   Rubygems      ●   Ivy
●   PEAR (PHP)
Modularity

              Your program


Library X              Library Y


 Library Z,             Library Z,
 version 1              version 2
"JAR hell"
                Your program

x.jar                 y.jar

 Library X               Library Y

   Library Z,                 Library Z,
   version 1                  version 2
CPAN
●   System-wide or per-user library installation
●   User manages libraries
●   One repository, many mirrors
●   Multiple versions of a lib may be installed;
    each process may only use one version
●   Integrated docs, tests, & bug tracker
Rubygems
●   System-wide or per-user library installation
●   User manages libraries
●   Multiple repositories, names may conflict
●   Multiple versions of a lib may be installed;
    each process may only use one version
●   Docs, tests, and bug tracking not integrated
ASDF
●   System-wide or per-user library installation
●   User manages libraries
●   Wiki page acts as the repository!
●   No integrated docs/tests/bug-tracking
●   Does not support multiple versions of the
    same lib
Maven / Ivy
●   Per-project library installation
●   Build system manages libraries;
    user manages private repository
●   Multiple public repositories
●   Optional integration with docs/tests
●   Permits multiple versions of a same lib,
    must be handled by a framework
OSGi
●   Java EE, Glassfish, Eclipse
●   Bundle: JAR file + extra manifest headers
●   Each Bundle gets its own ClassLoader
●   Multiple, nested ClassLoader contexts
    within a single JVM
More
●   http://clojure.org/
●   Google Groups: Clojure
●   #clojure on irc.freenode.net
●   http://github.com/richhickey/clojure-contrib
●   http://stuartsierra.com/
●   http://github.com/stuartsierra
●   http://www.altlaw.org/

More Related Content

PDF
Linker Wisdom
PPT
Os Vanrossum
PDF
Quick start bash script
ODP
Os Cook
PDF
Introduction to clojure
ODP
Clojure: Practical functional approach on JVM
PDF
Linux fundamental - Chap 14 shell script
PPTX
Shell Script Tutorial
Linker Wisdom
Os Vanrossum
Quick start bash script
Os Cook
Introduction to clojure
Clojure: Practical functional approach on JVM
Linux fundamental - Chap 14 shell script
Shell Script Tutorial

What's hot (20)

PPT
Unix Shell Scripting Basics
PPTX
system management -shell programming by gaurav raikar
PPT
Unix Shell Scripting Basics
PDF
Unix Shell Scripting
PDF
JAVA NIO
PPT
Shell Scripting
PPTX
Linux shell env
PDF
Shell scripting
ODP
Shellscripting
PPT
eZ Publish cluster unleashed revisited
PPT
NIO.2, the I/O API for the future
PDF
Shell scripting
PDF
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
PDF
お題でGroovyプログラミング: Part A
DOC
unix-OS-Lab-4.doc
PPT
Chap06
PPTX
PPTX
Basics of shell programming
PPT
Unix And Shell Scripting
PPTX
Unix shell scripting
Unix Shell Scripting Basics
system management -shell programming by gaurav raikar
Unix Shell Scripting Basics
Unix Shell Scripting
JAVA NIO
Shell Scripting
Linux shell env
Shell scripting
Shellscripting
eZ Publish cluster unleashed revisited
NIO.2, the I/O API for the future
Shell scripting
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
お題でGroovyプログラミング: Part A
unix-OS-Lab-4.doc
Chap06
Basics of shell programming
Unix And Shell Scripting
Unix shell scripting
Ad

Viewers also liked (8)

PDF
Hands On with Maven
PPTX
Maven for Dummies
PDF
Mastering Maven 2.0 In 1 Hour V1.3
PPT
Demystifying Maven
PPTX
An introduction to Maven
PPT
Maven Introduction
PDF
Continuous delivery-with-maven
PDF
Maven 2 in the real world
Hands On with Maven
Maven for Dummies
Mastering Maven 2.0 In 1 Hour V1.3
Demystifying Maven
An introduction to Maven
Maven Introduction
Continuous delivery-with-maven
Maven 2 in the real world
Ad

Similar to Clojure and Modularity (20)

PDF
Clojure - A new Lisp
ODP
Clojure made simple - Lightning talk
PDF
Clojure - A practical LISP for the JVM
PDF
Clojure made-simple - John Stevenson
KEY
(map Clojure everyday-tasks)
ODP
Clojure made really really simple
PDF
Pune Clojure Course Outline
PDF
Clojure talk at Münster JUG
PDF
Clojure Interoperability
ODP
Getting started with Clojure
KEY
Clojure Intro
ODP
Clojure presentation
PDF
Clojure - LISP on the JVM
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PDF
(first '(Clojure.))
PPTX
Clojure Fundamentals Course For Beginners
PDF
I know Java, why should I consider Clojure?
PDF
Clojure: Simple By Design
PDF
Fun with Functional Programming in Clojure
Clojure - A new Lisp
Clojure made simple - Lightning talk
Clojure - A practical LISP for the JVM
Clojure made-simple - John Stevenson
(map Clojure everyday-tasks)
Clojure made really really simple
Pune Clojure Course Outline
Clojure talk at Münster JUG
Clojure Interoperability
Getting started with Clojure
Clojure Intro
Clojure presentation
Clojure - LISP on the JVM
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
(first '(Clojure.))
Clojure Fundamentals Course For Beginners
I know Java, why should I consider Clojure?
Clojure: Simple By Design
Fun with Functional Programming in Clojure

More from elliando dias (20)

PDF
Clojurescript slides
PDF
Why you should be excited about ClojureScript
PDF
Functional Programming with Immutable Data Structures
PPT
Nomenclatura e peças de container
PDF
Geometria Projetiva
PDF
Polyglot and Poly-paradigm Programming for Better Agility
PDF
Javascript Libraries
PDF
How to Make an Eight Bit Computer and Save the World!
PDF
Ragel talk
PDF
A Practical Guide to Connecting Hardware to the Web
PDF
Introdução ao Arduino
PDF
Minicurso arduino
PDF
Incanter Data Sorcery
PDF
PDF
Fab.in.a.box - Fab Academy: Machine Design
PDF
The Digital Revolution: Machines that makes
PDF
Hadoop + Clojure
PDF
Hadoop - Simple. Scalable.
PDF
Hadoop and Hive Development at Facebook
PDF
Multi-core Parallelization in Clojure - a Case Study
Clojurescript slides
Why you should be excited about ClojureScript
Functional Programming with Immutable Data Structures
Nomenclatura e peças de container
Geometria Projetiva
Polyglot and Poly-paradigm Programming for Better Agility
Javascript Libraries
How to Make an Eight Bit Computer and Save the World!
Ragel talk
A Practical Guide to Connecting Hardware to the Web
Introdução ao Arduino
Minicurso arduino
Incanter Data Sorcery
Fab.in.a.box - Fab Academy: Machine Design
The Digital Revolution: Machines that makes
Hadoop + Clojure
Hadoop - Simple. Scalable.
Hadoop and Hive Development at Facebook
Multi-core Parallelization in Clojure - a Case Study

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx

Clojure and Modularity

  • 1. Clojure and Modularity Philly Lambda Tuesday, July 21, 2009 Stuart Sierra http://stuartsierra.com/
  • 3. Clojure's Four Elements List (print :hello "Philly") Vector [:eat "Pie" 3.14159] Map {:lisp 1 "The Rest" 0} Set #{2 1 3 5 "Eureka"}
  • 4. defn (defn greet [name] (println "Hello," name)) (defn average [& args] (/ (reduce + args) (count args)))
  • 5. Data are Functions ({:f "foo" :b "bar"} :f) "foo" (:key {:key "value", :x "y"}) "value" ([:a :b :c] 2) :c (#{1 5 3} 3) true
  • 6. defmacro (defmacro when [test & body] (list 'if test (cons 'do body)))
  • 7. Java (import '(com.example.package MyClass YourClass)) (.method object argument) (MyClass/staticMethod argument) (MyClass. argument)
  • 8. synchronous asynchronous coordinated ref independent atom agent unshared var
  • 9. Vars (def life 42) (defn meaning [] (println life)) (meaning) 42 (binding [life 37] (let [life 37] (println life) (meaning)) (meaning)) 37 37 42
  • 10. Refs (def c (ref 100)) (deref c) 100 (dosync (alter c inc)) (deref c) 101
  • 11. Agents (def fib (agent [1 1 2])) (deref fib) [1 1 2] (send fib conj 3 5) returns immediately! later on... (deref fib) [1 1 2 3 5]
  • 12. clojure.contrib.http.agent (http-agent "http://www.altlaw.org/" :on-success (fn [a] (println (response-body-str a))))
  • 13. Multimethods (defmulti copy (fn [in out] [(class in) (class out)]))
  • 14. Multimethods (defmethod copy [InputStream OutputStream] .. (defmethod copy [InputStream Writer] ... (defmethod copy [InputStream File] ... (defmethod copy [Reader OutputStream] ... (defmethod copy [Reader Writer] ... (defmethod copy [Reader File] ... (defmethod copy [File OutputStream] ... (defmethod copy [File Writer] ... (defmethod copy [File File] ...
  • 15. Namespaces (ns my.cool.project (:require [clojure.contrib.math :as math]) (:import (java.math BigDecimal))) (defn lower-median [x y] (math/floor (/ x y))
  • 16. Modularity and Dependency Management ● CPAN ● OSGi ● Python Eggs ● Maven ● Rubygems ● Ivy ● PEAR (PHP)
  • 17. Modularity Your program Library X Library Y Library Z, Library Z, version 1 version 2
  • 18. "JAR hell" Your program x.jar y.jar Library X Library Y Library Z, Library Z, version 1 version 2
  • 19. CPAN ● System-wide or per-user library installation ● User manages libraries ● One repository, many mirrors ● Multiple versions of a lib may be installed; each process may only use one version ● Integrated docs, tests, & bug tracker
  • 20. Rubygems ● System-wide or per-user library installation ● User manages libraries ● Multiple repositories, names may conflict ● Multiple versions of a lib may be installed; each process may only use one version ● Docs, tests, and bug tracking not integrated
  • 21. ASDF ● System-wide or per-user library installation ● User manages libraries ● Wiki page acts as the repository! ● No integrated docs/tests/bug-tracking ● Does not support multiple versions of the same lib
  • 22. Maven / Ivy ● Per-project library installation ● Build system manages libraries; user manages private repository ● Multiple public repositories ● Optional integration with docs/tests ● Permits multiple versions of a same lib, must be handled by a framework
  • 23. OSGi ● Java EE, Glassfish, Eclipse ● Bundle: JAR file + extra manifest headers ● Each Bundle gets its own ClassLoader ● Multiple, nested ClassLoader contexts within a single JVM
  • 24. More ● http://clojure.org/ ● Google Groups: Clojure ● #clojure on irc.freenode.net ● http://github.com/richhickey/clojure-contrib ● http://stuartsierra.com/ ● http://github.com/stuartsierra ● http://www.altlaw.org/