Clojure in 10 min

Clojure is probably the most conceptually minimalistic language you ever deal with. I mean general and practical languages. Clojure is a hosted by design language, i.e. it runs on existing platforms like JVM or JavaScript runtimes and does not pretend to be independent.

Clojure uses host's primitives:

(type 1) => int
(type "string") => java.lang.String
(type 1.0) => 

There are two "pure clojure" primitive types:

(type :namespace/keyword) => clojure.lang.Keyword
(type 'namespace/my-symbol) => clojure.lang.Symbol

Keywords are a special (internalized) strings with namespace, which are used as keys in hash-maps or as string constants. And symbols are used to name functions and other objects. You can use more special characters than you expect in symbols and keywords: :valid-key, '>>

The first important data structure is a list: (one two three)

TBD:

There are hash-maps for key-value containers, vectors for sequential data, and sets for unsorted sets of unique items:

{:key "value" :other-key 1}
[1 2 3 4]

The comma (,) is a space symbol in Clojure. The semicolon (;) starts comment till the end of the line

All Clojure "containers" are immutable. That means when you are trying to change data structure (add an item to vector or associate a new key into hash-map) - you will get a new updated "copy" without touching the original. It is important that this "copy" is cheap in terms of speed and memory! Clojure data structures are persistent data structures, with sophisticated design and this is one of Clojure pillars. Precisely because "cheap" immutable data structures you can carelessly exercise pure functional programming in Clojure.

You can define a function with special form fn or with macros defn:

(defn say-hi [message]
  (println "Hello, " message))

(say-hi "Clojre")
> Hello, Clojure

Last updated