{:check ["true"]}

Index

Getting Started

Prerequisite: JVM

  • Clojure compiles its programs natively to Java bytecode, so you will need a Java Runtime Environment (JRE) installed.

  • Clojure recommends JRE 1.8 (Java 8 runtime environment).

    $ java -version
    openjdk version "1.8.0_152-release"
    OpenJDK Runtime Environment (build 1.8.0_152-release-1056-b12)
    OpenJDK 64-Bit Server VM (build 25.152-b12, mixed mode)
    
  • However, we have confirmed that everything works fine with the latest JRE.

    $ java -version
    openjdk version "14.0.1" 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    

Cli

Clojure Installer

As REPL

Using clj as REPL: we can interactively evaluate code snippets.

$ clj
Clojure 1.10.1
user=> (println "Hello")
Hello
nil
user=>

As scripting language

  • Using clj as runtime environment: we can write small single-file Clojure programs and run them with clj.

    learn.clj

    (defn christmas-tree [n]
      (dotimes [i n]
        (let [spaces (apply str (repeat (- 3 i) " "))
              stars (apply str (repeat (inc (* 2 i)) "*"))]
          (println (str spaces stars))))
      (println (str (apply str (repeat (dec n) " ")) "|")))
    
    (christmas-tree 4)
    
  • We can run it:

    $ clj learn.clj
       *
      ***
     *****
    *******
       |
    

As build tool for larger projects