Browse Clojure Foundations for Java Developers

Lists

When to use Clojure’s immutable linked lists (mostly for code and stack-like operations) and how conj/cons/first/rest behave.

Lists in Clojure are immutable linked lists. You’ll see them constantly because Clojure code itself is written as lists, but for most domain data you’ll reach for vectors and maps.

When Lists Are a Good Fit

  • building at the front efficiently (conj, cons)
  • treating code as data (quoted lists, macroexpansion output)
  • recursive algorithms that naturally consume a head + tail

Creating Lists

Remember: an unquoted list usually means “call this.”

1(+ 1 2)     ; call
2'(+ 1 2)    ; data (quoted list)
3
4(list 1 2 3)      ; => (1 2 3)
5(cons 0 '(1 2 3)) ; => (0 1 2 3)

Reading Lists

1(first '(1 2 3)) ; => 1
2(rest  '(1 2 3)) ; => (2 3)

The Key Behavior: conj Adds to the Front

1(conj '(1 2) 3) ; => (3 1 2)

Practical Tip for Java Developers

If you want “an ordered bag of values,” default to vectors. Use lists when you specifically want stack-like behavior at the head or you’re working with code forms.

Knowledge Check: Lists

### What does `(conj '(1 2) 3)` evaluate to? - [x] `(3 1 2)` - [ ] `(1 2 3)` - [ ] `[1 2 3]` - [ ] It mutates the list and returns `nil`. > **Explanation:** `conj` adds in the most efficient place: for lists, that’s the front. ### Why would you write `'(+ 1 2)` instead of `(+ 1 2)`? - [x] To treat the form as data and prevent evaluation. - [ ] To make it run faster. - [ ] To call `+` with keyword arguments. - [ ] To force compilation of `+`. > **Explanation:** `quote` (the `'` reader macro) returns the unevaluated form. That’s how macros and code-analysis tools work. ### Which collection is the better default for indexed access? - [x] Vector - [ ] List - [ ] Set - [ ] None; Clojure has no indexed collections. > **Explanation:** Vectors are designed for efficient random access and are the most common choice for ordered data.
Revised on Friday, April 24, 2026