Browse Clojure Foundations for Java Developers

Basic Syntax and Data Types

How to read Clojure forms and the literals you’ll see most: numbers, strings, keywords, symbols, and nil.

Clojure’s syntax is tiny on purpose. Once you can read a form and recognize the common literals, you can navigate real code quickly.

Read Forms (Expressions), Not Statements

In Clojure, code is written as lists. The first element is the operator and the rest are arguments:

1(+ 1 2 3)        ; => 6
2(str "a" "b")    ; => "ab"
3(map inc [1 2])  ; => (2 3)

Two practical rules:

  • () usually means “call something.”
  • [], {}, and #{} usually mean “data.”

Unlike Java, there’s no “statement vs expression” split. Most forms evaluate to a value and can be nested.

Core Literals You’ll See Everywhere

Numbers

142     ; integer (long-ish)
23.14   ; double
31/2    ; ratio (exact fraction)
410N    ; bigint
52.5M   ; bigdecimal

Strings and characters

1"hello"    ; java.lang.String
2\a         ; character
3\newline   ; named character

Booleans and nil

Only false and nil are falsey. Everything else is truthy (including 0, "", [], and {}).

Keywords vs symbols (easy to confuse at first)

  • :user/id is a keyword (commonly used as a map key). Keywords are also callable for map lookup:

    1(:user/id {:user/id 42}) ; => 42
    
  • user/id is a symbol (a name that resolves to a var/function when evaluated).

Comments and reader tools

1; line comment
2#_(+ 1 2) ; ignore next form (handy in the REPL)

let vs def (local vs global)

Use let for local bindings (like Java locals):

1(let [x 1
2      y 2]
3  (+ x y))
4;; => 3

Use def for top-level vars (like Java static fields). As a rule of thumb: use def at the namespace boundary, not inside function bodies.

Knowledge Check: Basic Syntax

### In Clojure, which values are falsey? - [x] Only `nil` and `false` - [ ] `nil`, `false`, and `0` - [ ] `nil`, `false`, and empty collections - [ ] Anything that is “empty” > **Explanation:** Conditionals treat only `nil` and `false` as false. `0`, `""`, `[]`, and `{}` are all truthy. ### What does quoting do? (Example: `'(+ 1 2)`) - [x] It prevents evaluation and returns the form as data (a list). - [ ] It evaluates the form at compile time. - [ ] It converts the form into a string. - [ ] It evaluates the form in a separate namespace. > **Explanation:** `quote` (and the `'` reader macro) returns the unevaluated form. This is foundational for macros and code-as-data tooling. ### Which statement about keywords is true? - [x] Keywords are commonly used as map keys and can be called to look up their value in a map. - [ ] Keywords are mutable identifiers like Java variables. - [ ] Keywords always refer to functions in a namespace. - [ ] Keywords only exist for documentation strings. > **Explanation:** Keywords are immutable identifiers that shine as map keys. “Keyword-as-function” lookup is a common idiom in real code.
Revised on Friday, April 24, 2026