Fundamental Syntax and Concepts
Learn Clojure's compact syntax as a Java engineer: forms, literals, symbols, keywords, collections, namespaces, formatting, and the habits that make Clojure code readable at the REPL and in production.
Clojure’s syntax is small, but it looks unfamiliar if you expect Java’s class-first, statement-heavy shape. This chapter teaches you to read Clojure forms before you write large programs: lists as code, vectors/maps/sets as data, symbols as names, keywords as stable labels, and namespaces as the unit of organization.
For Java engineers, the key shift is learning to see shape quickly:
| Reading skill |
Java reflex to replace |
Clojure habit to build |
| Identify the outer form |
Look for statement type first |
Read the first position of the form |
| Separate code from data |
Treat all parentheses as grouping |
Lists are usually calls; vectors, maps, and sets are data literals |
| Follow names |
Expect class members and imports |
Track symbols, keywords, aliases, and namespaces |
| Predict results |
Ask what statement executes |
Ask what value the form returns |
| Keep code readable |
Depend on braces and declarations |
Use formatting, docstrings, and small REPL-tested forms |
Once you can scan Clojure code and predict what it evaluates to, the rest of the language becomes less mysterious. Keep a REPL handy and evaluate small forms as you go. In Clojure, syntax literacy comes from seeing values, not from memorizing grammar rules.
In this section
-
Symbols and Keywords
Learn the distinction Java engineers need early: symbols are names Clojure resolves in code, while keywords are self-evaluating labels used in data.
-
Symbols in Clojure
Understand symbols as Clojure names that resolve to locals, vars, namespace-qualified references, class names, or quoted code data.
-
Keywords in Clojure
Use Clojure keywords as self-evaluating labels for maps, statuses, options, qualified domain attributes, and data-first APIs.
-
Symbols vs Keywords in Clojure
Choose symbols for code-facing names and keywords for data-facing labels, with Java comparisons, map examples, review heuristics, and common migration mistakes.
-
Data Types
Understand Clojure's core scalar values on the JVM: numbers, strings, characters, booleans, nil, truthiness, and the interop details Java engineers need to recognize early.
-
Numbers in Clojure for Java Developers
Learn Clojure's numeric literals, ratios, BigInt and BigDecimal values, overflow behavior, equality rules, and JVM interop concerns without importing Java's primitive-first habits.
-
Strings in Clojure for Java Developers
Work with Clojure strings as JVM strings: immutable text values, clojure.string functions, regex operations, formatting, nil handling, and Java interop boundaries.
-
Characters, Booleans, and Truthiness
Understand Clojure character literals, boolean values, truthiness, nil, predicates, and conditional forms through the differences Java developers notice first.
-
Collections
Choose the right Clojure collection as a Java engineer: vectors for indexed ordered data, maps for domain records, sets for membership, lists for code-shaped sequences, and seqs for generic traversal.
-
Lists in Clojure
Understand Clojure lists as immutable head-first sequences, code forms, and occasional data structures, while avoiding Java List assumptions about indexed access.
-
Vectors in Clojure
Use Clojure vectors as the default ordered collection for indexed, immutable data, with practical guidance on conj, assoc, subvec, sequence functions, and Java ArrayList comparisons.
-
Maps in Clojure
Use Clojure maps as immutable records and lookup tables with keyword keys, assoc, update, dissoc, merge, nested updates, and Java HashMap comparisons.
-
Sets in Clojure
Use Clojure sets for uniqueness, membership checks, set algebra, deduplication, and Java Set comparisons while preserving immutable value semantics.
-
Expressions and S-Expressions
Read and write Clojure expressions by understanding prefix form structure, evaluation order, special forms, macro expansion, and the difference between code lists and data literals.
-
Comments and Docstrings
Document Clojure code with useful line comments, reader-discard forms, REPL-friendly comment blocks, and docstrings that help Java teams understand functions without importing Javadoc habits blindly.
-
Namespaces and Requires
Organize Clojure code with ns, require aliases, selective refer, Java imports, and namespace hygiene that keeps symbol origins clear for Java engineers.
-
Clojure Style and Formatting
Write readable Clojure with idiomatic indentation, kebab-case names, predicate and mutation markers, namespace-aware formatting, and formatter habits that reduce code review noise.
-
Syntax Differences From Java
Compare Java syntax habits with Clojure form-reading habits: prefix calls, expression-oriented conditionals, immutable bindings, data literals, threading macros, and JVM interop shapes.
-
Clojure Syntax Practice
Practice Clojure syntax with Java-to-Clojure rewrites that use maps, vectors, sequence transformations, let bindings, REPL checks, and immutable update patterns.
-
Syntax Chapter Review
Review the Clojure syntax chapter by connecting forms, literals, collections, symbols, keywords, namespaces, style, Java syntax differences, and practice habits into one working mental model.