1. The Clojure Ecosystem

ecosystem

Integrity is an ecosystem.
— Michael Leunig

Dependencies

  • Libraries are plain old jars

  • Clojure is itself a jar

  • Clojure can make direct use of other jars

  • Easy to deploy

  • Leiningen

Leiningen

lein new training
cd training
tree
cat project.clj
cat src/training/core.clj

tree

.
├── CHANGELOG.md
├── doc
│   └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│   └── training
│       └── core.clj
└── test
    └── training
        └── core_test.clj

project.clj

(defproject training "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license
  {:name "Eclipse Public License"
   :url "http://www.eclipse.org/legal/epl-v10.html"}
   :dependencies [[org.clojure/clojure "1.8.0"]])

src/training/core.clj

(ns training.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

The Read Eval Print Loop (REPL)

$ lein repl

We type in an expression:

(+ 1 2)

Clojure returns a result:

=> 3
means evaluates to

Editor setup

  • IntelliJ IDEA + Cursive

  • Wide range of editor support options

Exercises

See manual end of section 1

Answers a

(+ 2 3)
;=> 5
(* 31 79)
;=> 2449
(/ 10 2)
;=> 5
(/ 2 10)
;=> 1/5

Answers b

(+ 1 2 3)
;=> 6

(println "hello world") ;⇒ "hello world"

(* 5 4 3 2 1)
;=> 120

End Ecosystem