Clojure: Syntax, Immutability & the Seq Abstraction
Clojure is a modern, functional Lisp dialect running primarily on the JVM -- immutability and simplicity are central design goals, with seamless interoperability with existing Java libraries.
Lisp Syntax: Code as Nested Lists
(+ 1 2 3) ; => 6 -- the function comes FIRST, inside parens
(defn greet [name]
(str "Hello, " name "!"))
(greet "Alice") ; => "Hello, Alice!"Immutability by Default
(def original [1 2 3])
(def updated (conj original 4))
original ; => [1 2 3] -- unchanged
updated ; => [1 2 3 4] -- a NEW vector
; Persistent data structures share unchanged internal structure
; between old/new versions -- not a naive full copy on every change,
; making immutability practically efficient at real-world scaleKeywords & Map Lookup
(def person {:name "Alice" :age 30})
(:name person) ; => "Alice" -- keyword used AS a function
(get person :age) ; => 30 -- equivalent, more explicit formThe Seq Abstraction: One API, Many Collections
; The SAME map function works across a vector, a list, and a set --
; no separate specialized version needed per collection type
(map inc [1 2 3]) ; => (2 3 4)
(map inc '(1 2 3)) ; => (2 3 4)
(map inc #{1 2 3}) ; => (2 3 4)Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free